From 0de25020073b38aa4739f0655e3cf9666b134eb1 Mon Sep 17 00:00:00 2001 From: Omar Moreno Date: Wed, 24 Oct 2018 13:50:02 -0700 Subject: [PATCH 001/314] Initial commit --- .gitignore | 32 ++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..259148fa1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/README.md b/README.md new file mode 100644 index 000000000..b1128fd63 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# hpstr +Heavy Photon Search Toolkit for Reconstruction From 0b2fbf32eb574d4b7e7e083d80df8e4434edd290 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:42:13 -0700 Subject: [PATCH 002/314] Utility class that reads/executes a python script and creates a Process object based on the input. --- processing/include/ConfigurePython.h | 83 ++++++++++ processing/src/ConfigurePython.cxx | 237 +++++++++++++++++++++++++++ 2 files changed, 320 insertions(+) create mode 100644 processing/include/ConfigurePython.h create mode 100644 processing/src/ConfigurePython.cxx diff --git a/processing/include/ConfigurePython.h b/processing/include/ConfigurePython.h new file mode 100644 index 000000000..fc4d2b9a3 --- /dev/null +++ b/processing/include/ConfigurePython.h @@ -0,0 +1,83 @@ +/** + * @file ConfigurePython.h + * @brief Utility class that reads/executes a python script and creates a + * Process object based on the input. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __CONFIGURE_PYTHON_H__ +#define __CONFIGURE_PYTHON_H__ + +//------------// +// Python // +//------------// +#include "Python.h" + +//----------------// +// C++ StdLib // +//----------------// +#include +#include +#include +#include + +//------------// +// svt-qa // +//------------// +#include "Process.h" +#include "ProcessorFactory.h" + +class ConfigurePython { + + + public: + + /** + * Class constructor. + * + * This method contains all the parsing and execution of the python script. + * + * @param pythonScript Filename location of the python script. + * @param args Commandline arguments to be passed to the python script. + * @param nargs Number of commandline arguments. + */ + ConfigurePython(const std::string& pythonScript, char* args[], int nargs); + + /** + * Class destructor. + */ + ~ConfigurePython(); + + /** Create a process object based on the python file information. */ + Process* makeProcess(); + + private: + + /** The maximum number of events to process, if provided in python file. */ + int event_limit_{-1}; + + /** List of input files to process in the job, if provided in python file. */ + std::vector input_files_; + + /** List of rules for shared libraries to load, if provided in python file. */ + std::vector libraries_; + + /** List of rules for output ROOT file names, if provided in python file. */ + std::vector output_files_; + + /** + * @struct ProcessorInfo + * @brief Represents the configuration of an EventProcessor in the job. + */ + struct ProcessorInfo { + std::string classname_; + std::string instancename_; + //ParameterSet params_; + }; + + /** The sequence of EventProcessor objects to be executed in order. */ + std::vector sequence_; + +}; + +#endif // __CONFIGURE_PYTHON_H__ diff --git a/processing/src/ConfigurePython.cxx b/processing/src/ConfigurePython.cxx new file mode 100644 index 000000000..f3f71b14b --- /dev/null +++ b/processing/src/ConfigurePython.cxx @@ -0,0 +1,237 @@ +/** + * @file ConfigurePython.cxx + * @brief Utility class that reads/executes a python script and creates a + * Process object based on the input. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "ConfigurePython.h" + +static std::string stringMember(PyObject* owner, const std::string& name) { + + std::string retval; + PyObject* temp = PyObject_GetAttrString(owner, name.c_str()); + if (temp != 0) { + retval = PyString_AsString(temp); + Py_DECREF(temp); + } + return retval; +} + + +static long intMember(PyObject* owner, const std::string& name) { + + long retval; + PyObject* temp = PyObject_GetAttrString(owner, name.c_str()); + if (temp != 0) { + retval = PyInt_AsLong(temp); + Py_DECREF(temp); + } + return retval; +} + + +ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], int nargs) { + + std::string path("."); + std::string cmd = python_script; + + // if a path was specified, extract it and the command + if (python_script.rfind("/") != std::string::npos) { + path = python_script.substr(0, python_script.rfind("/")); + cmd = python_script.substr(python_script.rfind("/") + 1); + } + cmd = cmd.substr(0, cmd.find(".py")); + + // Initialize the python interpreter. + Py_Initialize(); + + // Set the command line arguments passed to the python script to be + // executed. Note that the first parameter in the list or arguments + // should refer to the script to be executed. + if (nargs > 0) { + char** targs = new char*[nargs + 1]; + targs[0] = (char*) python_script.c_str(); + for (int i = 0; i < nargs; i++) + targs[i + 1] = args[i]; + PySys_SetArgvEx(nargs, targs, 1); + delete[] targs; + } + + PyObject* script = nullptr; + PyObject* process = nullptr; + PyObject* p_main = nullptr; + PyObject* py_list = nullptr; + PyObject* p_process = nullptr; + + // Load the python script. + script = PyImport_ImportModule(cmd.c_str()); + Py_DECREF(script); + + try { + + // If a reference to the python script couldn't be created, raise + // an exception. + if (script == 0) { + PyErr_Print(); + throw std::runtime_error("[ ConfigurePython ]: Problem loading python script."); + } + + // Load the script that is used create a processor + PyObject* pCMod = PyObject_GetAttrString(script, "HpstrConf"); + if (pCMod == 0) { + PyErr_Print(); + throw std::runtime_error("[ ConfigurePython ]: Problem loading configuration"); + } + + PyObject* p_process_class = PyObject_GetAttrString(pCMod, "Process"); + Py_DECREF(pCMod); + if (p_process_class == 0) { + PyErr_Print(); + throw std::runtime_error("[ ConfigurePython ]: Problem loading Process class"); + } + + p_process = PyObject_GetAttrString(p_process_class, "lastProcess"); + Py_DECREF(p_process_class); + if (p_process == 0) { + PyErr_Print(); + throw std::runtime_error("[ ConfigurePython ]: Problem loading Process class"); + } + + event_limit_ = intMember(p_process, "max_events"); + + PyObject* p_sequence = PyObject_GetAttrString(p_process, "sequence"); + if (!PyList_Check(p_sequence)) { + throw std::runtime_error("[ ConfigurePython ]: Sequence is not a python list as expected."); + } + + for (Py_ssize_t i = 0; i < PyList_Size(p_sequence); i++) { + PyObject* processor = PyList_GetItem(p_sequence, i); + ProcessorInfo pi; + pi.classname_ = stringMember(processor, "class_name"); + pi.instancename_ = stringMember(processor, "instance_name"); + std::cout << pi.classname_ << std::endl; + std::cout << "Hereeeeeee:" << std::endl; + + /* + PyObject* params = PyObject_GetAttrString(processor, "parameters"); + if (params != 0 && PyDict_Check(params)) { + PyObject *key(0), *value(0); + Py_ssize_t pos = 0; + + while (PyDict_Next(params, &pos, &key, &value)) { + std::string skey = PyString_AsString(key); + if (PyBool_Check(value)) { + pi.params_.insert(skey, bool(PyInt_AsLong(value))); + //printf("Bool Key: %s\n",skey.c_str()); + } else if (PyInt_Check(value)) { + pi.params_.insert(skey, int(PyInt_AsLong(value))); + //printf("Int Key: %s\n",skey.c_str()); + } else if (PyFloat_Check(value)) { + pi.params_.insert(skey, PyFloat_AsDouble(value)); + //printf("Double Key: %s\n",skey.c_str()); + } else if (PyString_Check(value)) { + pi.params_.insert(skey, PyString_AsString(value)); + //printf("String Key: %s\n",skey.c_str()); + } else if (PyList_Check(value)) { // assume everything is same value as first value + if (PyList_Size(value) > 0) { + PyObject* vec0 = PyList_GetItem(value, 0); + if (PyInt_Check(vec0)) { + std::vector vals; + for (Py_ssize_t j = 0; j < PyList_Size(value); j++) + vals.push_back(PyInt_AsLong(PyList_GetItem(value, j))); + pi.params_.insert(skey, vals); + //printf("VInt Key: %s\n",skey.c_str()); + } else if (PyFloat_Check(vec0)) { + std::vector vals; + for (Py_ssize_t j = 0; j < PyList_Size(value); j++) + vals.push_back(PyFloat_AsDouble(PyList_GetItem(value, j))); + pi.params_.insert(skey, vals); + //printf("VDouble Key: %s\n",skey.c_str()); + } else if (PyString_Check(vec0)) { + std::vector vals; + for (Py_ssize_t j = 0; j < PyList_Size(value); j++) + vals.push_back(PyString_AsString(PyList_GetItem(value, j))); + pi.params_.insert(skey, vals); + //printf("VString Key: %s\n",skey.c_str()); + } + } + } + } + }*/ + + sequence_.push_back(pi); + } + Py_DECREF(p_sequence); + + py_list = PyObject_GetAttrString(p_process, "input_files"); + if (!PyList_Check(py_list)) { + throw std::runtime_error("[ ConfigurePython ]: Input files is not a python list as expected."); + return; + } + for (Py_ssize_t i = 0; i < PyList_Size(py_list); i++) { + PyObject* elem = PyList_GetItem(py_list, i); + input_files_.push_back(PyString_AsString(elem)); + } + Py_DECREF(py_list); + + py_list = PyObject_GetAttrString(p_process, "output_files"); + if (!PyList_Check(py_list)) { + throw std::runtime_error("[ ConfigurePython ]: Output files is not a python list as expected."); + return; + } + for (Py_ssize_t i = 0; i < PyList_Size(py_list); i++) { + PyObject* elem = PyList_GetItem(py_list, i); + output_files_.push_back(PyString_AsString(elem)); + } + Py_DECREF(py_list); + + py_list = PyObject_GetAttrString(p_process, "libraries"); + if (!PyList_Check(py_list)) { + throw std::runtime_error("[ ConfigurePython ]: libraries is not a python list as expected."); + return; + } + for (Py_ssize_t i = 0; i < PyList_Size(py_list); i++) { + PyObject* elem = PyList_GetItem(py_list, i); + libraries_.push_back(PyString_AsString(elem)); + } + Py_DECREF(py_list); + + } catch (std::exception& e) { + std::cout << e.what() << std::endl; + } + +} + +ConfigurePython::~ConfigurePython() { + Py_Finalize(); +} + +Process* ConfigurePython::makeProcess() { + Process* p = new Process(); + + for (auto lib : libraries_) { + ProcessorFactory::instance().loadLibrary(lib); + } + + for (auto proc : sequence_) { + Processor* ep = ProcessorFactory::instance().createProcessor(proc.classname_, proc.instancename_, *p); + if (ep == 0) { + throw std::runtime_error("[ ConfigurePython ]: Unable to create instance of " + proc.instancename_); + } + //ep->configure(proc.params_); + p->addToSequence(ep); + } + + for (auto file : input_files_) { + p->addFileToProcess(file); + } + + for (auto file : output_files_) { + p->addOutputFileName(file); + } + + p->setEventLimit(event_limit_); + + return p; +} From 0da870c50888724d6db3539536b4aaa9a2468024 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:43:39 -0700 Subject: [PATCH 003/314] Class which represents the process under execution. --- processing/include/Process.h | 90 ++++++++++++++++++++++++++++++++++++ processing/src/Process.cxx | 77 ++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 processing/include/Process.h create mode 100644 processing/src/Process.cxx diff --git a/processing/include/Process.h b/processing/include/Process.h new file mode 100644 index 000000000..491f654b6 --- /dev/null +++ b/processing/include/Process.h @@ -0,0 +1,90 @@ +/** + * @file Process.h + * @brief Class which represents the process under execution. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __PROCESS_H__ +#define __PROCESS_H__ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include + +//------------// +// svt-qa // +//------------// +#include "Processor.h" + +class Process { + + public: + + /** + * Class constructor. + * @param passname Processing pass label + */ + Process(); + + /** + * Add an event processor to the linear sequence of processors to run in this job + * @param event_proc Processor to add to the sequence + */ + void addToSequence(Processor* event_proc); + + /** + * Add an input file name to the list. + * @param filename Input ROOT event file name + */ + void addFileToProcess(const std::string& filename); + + /** + * Add an output file name to the list. There should either be the same number + * of output file names as input file names or just one output file name. + * @param output_filename Output ROOT event file name + */ + void addOutputFileName(const std::string& output_filename); + + /** + * Set the maximum number of events to process. Processing will stop + * when either there are no more input events or when this number of events have been processed. + * @param event_limit Maximum number of events to process. -1 indicates no limit. + */ + void setEventLimit(int event_limit=-1) { + event_limit_=event_limit; + } + + /** Run the process. */ + void run(); + + /** Request that the processing finish with this event. */ + void requestFinish() { event_limit_=0; } + + private: + + /** Reader used to parse either binary or EVIO files. */ + //DataRead* data_reader{nullptr}; + + /** Limit on events to process. */ + int event_limit_{-1}; + + /** Ordered list of Processors to execute. */ + std::vector sequence_; + + /** List of input files to process. May be empty if this Process will generate new events. */ + std::vector input_files_; + + /** List of output file names. If empty, no output file will be created. */ + std::vector output_files_; + +}; + +#endif diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx new file mode 100644 index 000000000..4d1e3821f --- /dev/null +++ b/processing/src/Process.cxx @@ -0,0 +1,77 @@ +/** + * @file Process.cxx + * @brief Class which represents the process under execution. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "Process.h" + +Process::Process() {} + +void Process::run() { + + try { + + int n_events_processed = 0; + + if (input_files_.empty()) + throw std::runtime_error("Please specify files to process."); + + //data_reader = new DataRead(); + //TrackerEvent event; + + int cfile = 0; + for (auto ifile : input_files_) { + + // Open the input file. If the input file can't be opened, exit + // the application. + //if (!data_reader->open(ifile.c_str(), false)) + // throw std::runtime_error("Error! File " + ifile + " cannot be opened."); + + std::cout << "---- [ svt-qa ][ Process ]: Processing file " + << ifile << std::endl; + + // Open the output file where all histograms will be stored. + TFile* ofile = new TFile(output_files_[cfile].c_str(), "RECREATE"); + + // first, notify everyone that we are starting + for (auto module : sequence_) { + module->initialize(); + } + + + //while (data_reader->next(&event)) { + // for (auto module : sequence_) { + // module->process(&event); + // } + //} + ++cfile; + + for (auto module : sequence_) { + module->finalize(); + } + + if (ofile) { + ofile->Write(); + delete ofile; + ofile = nullptr; + } + } + + } catch (std::exception& e) { + std::cerr << "---- [ svt-qa ][ Process ]: Error! " << e.what() << std::endl; + } +} + +void Process::addFileToProcess(const std::string& filename) { + input_files_.push_back(filename); +} + +void Process::addOutputFileName(const std::string& output_filename) { + output_files_.push_back(output_filename); +} + +void Process::addToSequence(Processor* mod) { + sequence_.push_back(mod); +} + From 1f6ec16fd369cb46f337fbf396a081c564534b18 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:44:55 -0700 Subject: [PATCH 004/314] Class which provides a singleton module factory that creates Processor objects. --- processing/include/ProcessorFactory.h | 90 +++++++++++++++++++++++++++ processing/src/ProcessorFactory.cxx | 57 +++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 processing/include/ProcessorFactory.h create mode 100644 processing/src/ProcessorFactory.cxx diff --git a/processing/include/ProcessorFactory.h b/processing/include/ProcessorFactory.h new file mode 100644 index 000000000..266363b41 --- /dev/null +++ b/processing/include/ProcessorFactory.h @@ -0,0 +1,90 @@ +/** + * @file ProcessorFactory.h + * @brief Class which provides a singleton module factory that creates Processor + * objects + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __PROCESSOR_FACTORY_H__ +#define __PROCESSOR_FACTORY_H__ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include +#include +#include + + +// +#include "Processor.h" + +class ProcessorFactory { + + public: + + /** + * Get the factory instance. + * @return The factory. + */ + static ProcessorFactory& instance() { + + /** Factory for creating the Processor object. */ + static ProcessorFactory instance_; + + return instance_; + } + + /** + * Register the event processor. + * @param classname The name of the class associated with processor. + * @param classtype The type of class associated with processor. + * @param maker TODO. + */ + void registerProcessor(const std::string& classname, ProcessorMaker* maker); + + /** + * Get the classes associated with the processor. + * @return a vector of strings corresponding to processor classes. + */ + //std::vector getProcessorClasses() const; + + /** + * Make an event processor. + * @param classname Class name of event processor. + * @param module_instance_name TODO. + * @param process The process type to create. + */ + Processor* createProcessor(const std::string& classname, const std::string& module_instance_name, Process& process); + + /** + * Load a library. + * @param libname The library to load. + */ + void loadLibrary(const std::string& libname); + + private: + + /** Constructor */ + ProcessorFactory() {}; + + /** + * @struct ProcessorInfo + * @brief Processor info container to hold classname, class type and maker. + */ + struct ProcessorInfo { + std::string classname; + ProcessorMaker* maker; + }; + + /** A map of names to processor containers. */ + std::map module_info_; + + + /** A set of names of loaded libraries. */ + std::set libs_loaded_; + +}; + +#endif // ProcessorFactory diff --git a/processing/src/ProcessorFactory.cxx b/processing/src/ProcessorFactory.cxx new file mode 100644 index 000000000..2bc845f92 --- /dev/null +++ b/processing/src/ProcessorFactory.cxx @@ -0,0 +1,57 @@ +/** + * @file ProcessorFactory.cxx + * @brief Class which provides a singleton module factory that creates Processor + * objects + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "ProcessorFactory.h" + +#include + +void ProcessorFactory::registerProcessor(const std::string& classname, ProcessorMaker* maker) { + auto ptr = module_info_.find(classname); + if (ptr != module_info_.end()) { + std::cout << "Error: " << std::endl; + } + ProcessorInfo mi; + mi.classname = classname; + mi.maker = maker; + module_info_[classname] = mi; +} + +/* +std::vector ProcessorFactory::getProcessorClasses() const { + std::vector classes; + for (auto ptr : module_info_) { + classes.push_back(ptr.first); + } + return classes; +} +*/ + +Processor* ProcessorFactory::createProcessor(const std::string& classname, const std::string& module_instance_name, Process& process) { + auto ptr = module_info_.find(classname); + if (ptr == module_info_.end()) { + return 0; + } + return ptr->second.maker(module_instance_name, process); +} + +void ProcessorFactory::loadLibrary(const std::string& libname) { + + std::cout << "[ ProcessorFactory ]: Loading library " << libname << std::endl; + + if (libs_loaded_.find(libname) != libs_loaded_.end()) { + return; // already loaded + } + + void* handle = dlopen(libname.c_str(), RTLD_NOW); + if (handle == NULL) { + std::cout << dlerror() << std::endl; + throw std::runtime_error("[ ProcessorFactory ]: Error loading library " + libname + ": " + dlerror()); + } + + libs_loaded_.insert(libname); +} + From 009aea6f925ddc4a50bd9381c1b51a35c49acb2e Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:46:20 -0700 Subject: [PATCH 005/314] Base class for all user event processing components to extend. --- processing/include/Processor.h | 107 +++++++++++++++++++++++++++++++++ processing/src/Processor.cxx | 16 +++++ 2 files changed, 123 insertions(+) create mode 100644 processing/include/Processor.h create mode 100644 processing/src/Processor.cxx diff --git a/processing/include/Processor.h b/processing/include/Processor.h new file mode 100644 index 000000000..174d5be76 --- /dev/null +++ b/processing/include/Processor.h @@ -0,0 +1,107 @@ +/** + * @file Processor.h + * @brief Base classes for all user event processing components to extend + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __PROCESSOR_H__ +#define __PROCESSOR_H__ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//---------// +// DAQ // +//---------// +//#include "TrackerEvent.h" + +// Forward declarations +class Process; +class Processor; + +/** Typedef for ProcessorFactory use. */ +typedef Processor* ProcessorMaker(const std::string& name, Process& process); + +/** + * @class Processor + * @brief Base class for all event processing components + */ +class Processor { + + public: + + /** + * Class constructor. + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided by the framework. + * + * @note The name provided to this function should not be + * the class name, but rather a logical label for this instance of + * the class, as more than one copy of a given class can be loaded + * into a Process with different parameters. Names should not include + * whitespace or special characters. + */ + Processor(const std::string& name, Process& process); + + /** + * Class destructor. + */ + virtual ~Processor() {;} + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + //virtual void process(TrackerEvent* event) = 0; + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts, such as + * creating histograms. + */ + virtual void initialize() = 0; + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes, such as + * calculating job-summary quantities. + */ + virtual void finalize() = 0; + + /** + * Callback for the Processor to configure itself from the given set of parameters. + * @param parameters ParameterSet for configuration. + */ + //virtual void configure(const ParameterSet& parameters) { + //} + + /** + * Internal function which is part of the ProcessorFactory machinery. + * @param classname The class name of the processor. + * @param classtype The class type of the processor (1 for Producer, 2 for Analyzer). + */ + static void declare(const std::string& classname, ProcessorMaker*); + + protected: + + /** Handle to the Process. */ + Process& process_; + + private: + + /** The name of the Processor. */ + std::string name_; + +}; + +/** + * @def DECLARE_PROCESSOR(CLASS) + * @param CLASS The name of the class to register, which must not be in a namespace. + * @brief Macro which allows the framework to construct a producer given its name during configuration. + * @attention Every Producer class must call this macro in the associated implementation (.cxx) file. + */ +#define DECLARE_PROCESSOR(CLASS) Processor* CLASS ## _make (const std::string& name, Process& process) { return new CLASS(name,process); } __attribute__((constructor(1000))) static void CLASS ## _declare() { Processor::declare(#CLASS, & CLASS ## _make ); } + +#endif diff --git a/processing/src/Processor.cxx b/processing/src/Processor.cxx new file mode 100644 index 000000000..e48577374 --- /dev/null +++ b/processing/src/Processor.cxx @@ -0,0 +1,16 @@ +/** + * @file Processor.cxx + * @brief Base classes for all user event processing components to extend + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "Processor.h" +#include "ProcessorFactory.h" + +Processor::Processor(const std::string& name, Process& process) : + process_ (process ), name_ { name } { +} + +void Processor::declare(const std::string& classname, ProcessorMaker* maker) { + ProcessorFactory::instance().registerProcessor(classname, maker); +} From 2f4eeba54bc0fa67516b547c6c5f409cdb58a893 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:47:37 -0700 Subject: [PATCH 006/314] Python module describing the process and processor classes. --- processing/python/HpstrConf.py | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 processing/python/HpstrConf.py diff --git a/processing/python/HpstrConf.py b/processing/python/HpstrConf.py new file mode 100644 index 000000000..1a7d014ae --- /dev/null +++ b/processing/python/HpstrConf.py @@ -0,0 +1,48 @@ + +class Processor: + + def __init__(self, instance_name, class_name): + self.instance_name = instance_name + self.class_name = class_name + + def toString(self): + print "\tProcessor( %s of instance %s )" % (self.instance_name, self.class_name) + +class Process: + + lastProcess=None + + def __init__(self): + self.max_events = -1 + self.input_files = [] + self.output_files = [] + self.sequence = [] + self.libraries = [] + Process.lastProcess=self + + def printProcess(self): + + if (self.max_events > 0): print " Maximum events to process: %d" % (self.max_events) + else: " No limit on maximum events to process" + + print "Processor sequence:" + for proc in self.sequence: + proc.toString() + if len(self.input_files) > 0: + if len(self.output_files)==len(self.input_files): + print "Files:" + for i in range(0,len(self.input_files)): + print " '%s' -> '%s'"%(self.input_files[i],self.output_files[i]) + else: + print "Input files:" + for afile in self.input_files: + print " %s"%(afile) + if len(self.output_files) > 0: + print "Output file:", self.output_files[0] + elif len(self.output_files) > 0: + print "Output file:", self.output_files[0] + if len(self.libraries) > 0: + print "Shared libraries to load:" + for afile in self.libraries: + print " %s"%(afile) + From 8b31b069b9251c80cef37a6b0e3847ea22f8ba07 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:48:38 -0700 Subject: [PATCH 007/314] App used to create and analyze HPS DST files. --- processing/src/hpstr.cxx | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 processing/src/hpstr.cxx diff --git a/processing/src/hpstr.cxx b/processing/src/hpstr.cxx new file mode 100644 index 000000000..b6f4621f0 --- /dev/null +++ b/processing/src/hpstr.cxx @@ -0,0 +1,84 @@ +/** + * @file hpstr.cxx + * @brief App used to create and analyze HPS DST files. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include +#include +#include +#include + +//-----------// +// hpstr // +//-----------// +#include "ConfigurePython.h" + +using namespace std; + +void displayUsage(); + +int main(int argc, char **argv) { + + if (argc < 2) { + displayUsage(); + return EXIT_FAILURE; + } + + int ptrpy = 1; + for (ptrpy = 1; ptrpy < argc; ptrpy++) { + std::cout << argv[ptrpy] << std::endl; + if (strstr(argv[ptrpy], ".py")) + break; + } + + if (ptrpy == argc) { + displayUsage(); + printf(" ** No python script provided. **\n"); + return EXIT_FAILURE; + } + + try { + + std::cout << "---- [ hpstr ]: Loading configuration --------" << std::endl; + + ConfigurePython cfg(argv[ptrpy], argv + ptrpy + 1, argc - ptrpy); + + std::cout << "---- [ hpstr ]: Configuration load complete --------" << std::endl; + + Process* p = cfg.makeProcess(); + + std::cout << "---- [ hpstr ]: Process initialized. --------" << std::endl; + + // If Ctrl-c is used, immediately exit the application. + struct sigaction act; + memset (&act, '\0', sizeof(act)); + if (sigaction(SIGINT, &act, NULL) < 0) { + perror ("sigaction"); + return 1; + } + + std::cout << "---- [ hpstr ]: Starting event processing --------" << std::endl; + + p->run(); + + std::cout << "---- [ hpstr ]: Event processing complete --------" << std::endl; + + } catch (exception& e) { + //std::cerr << "Error! [" << e.name() << "] : " << e.message() << std::endl; + //std::cerr << " at " << e.module() << ":" << e.line() << " in " << e.function() << std::endl; + + } + + return EXIT_SUCCESS; + +} + +void displayUsage() { + printf("Usage: hpstr [application arguments] {configuration_script.py}" + " [arguments to configuration script]\n"); +} From 657e165cc1a08acbc38d5c0d1162e7b622c7e323 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:49:10 -0700 Subject: [PATCH 008/314] Add build files. --- CMakeLists.txt | 82 +++++++++++++++++++++++++++++++++++++++ processing/CMakeLists.txt | 8 ++++ 2 files changed, 90 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 processing/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..10d221497 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,82 @@ +# minimum cmake version +cmake_minimum_required(VERSION 3.0) + +# find Python installation +find_package(PythonLibs REQUIRED) +message(STATUS "Python lib found at: ${PYTHON_LIBRARIES}") +message(STATUS "Python include dir found at: ${PYTHON_INCLUDE_DIRS}") +get_filename_component(PYTHON_LIBRARY_DIR ${PYTHON_LIBRARIES} DIRECTORY) + +# find ROOT installation +find_package(ROOT REQUIRED COMPONENTS Core RIO PyROOT Geom Eve Gui) +message(STATUS "ROOT found at: ${ROOT_DIR}") + +# option to print extra module information during CMake config +option(MODULE_DEBUG "Print extra module information during CMake config" OFF) + +# add dir with extra CMake modules +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules/) + +# import macro for declaring modules +include(MacroModule) + +# import macro for declaring external dependencies +include(MacroExtDeps) + +# declare list of modules with correct dependency order +#set(MODULES Event Framework DetDescr Tools EventProc SimCore SimPlugins Biasing SimApplication Configuration Detectors Ecal EventDisplay) + +set(MODULES processing) + +# build each module in the list +foreach(module ${MODULES}) + message(STATUS "Adding module: ${module}") + add_subdirectory(${module}) +endforeach() + +# install python init file for top-level LDMX module +#file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/python/__init__.py "# python package") +#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/python/__init__.py DESTINATION lib/python/LDMX) + +# configure and generate documentation using doxygen +#option(INSTALL_DOC "Set to ON to generate documentation using doxygen" OFF) +#message(STATUS "Doxygen documentation: ${INSTALL_DOC}") +#if(INSTALL_DOC) + + # message that documentation is off for this build + # message(STATUS "Doxygen documentation will be generated") + + # find doxygen + # find_program(DOXYGEN_EXECUTABLE doxygen ${PATH}) + # if(DOXYGEN_EXECUTABLE-NOTFOUND) + # message(FATAL_ERROR "The doxygen executable was not found") + # endif() + + # find dot + #find_program(DOT_EXECUTABLE dot ${PATH}) + #if(DOT_EXECUTABLE-NOTFOUND) + # message(FATAL_ERROR "The dot executable was not found.") + #endif() + + # configure doxygen file + # configure_file(${PROJECT_SOURCE_DIR}/docs/doxygen.conf.in ${PROJECT_SOURCE_DIR}/docs/doxygen.conf) + + # generate the documentation + # install(CODE "execute_process(COMMAND doxygen ${PROJECT_SOURCE_DIR}/docs/doxygen.conf WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})") + + # documentation generation target + # add_custom_target(doc COMMAND doxygen ${PROJECT_SOURCE_DIR}/docs/doxygen.conf) + + #endif() + +# option for dumping full CMake env +option(DUMP_CMAKE_VARIABLES OFF) +if(DUMP_CMAKE_VARIABLES) + get_cmake_property(_variableNames VARIABLES) + foreach(_variableName ${_variableNames}) + message(STATUS "${_variableName}=${${_variableName}}") + endforeach() +endif() + +# info message about install prefix +message(STATUS "hpstr will be installed to: ${CMAKE_INSTALL_PREFIX}") diff --git a/processing/CMakeLists.txt b/processing/CMakeLists.txt new file mode 100644 index 000000000..de4fe581e --- /dev/null +++ b/processing/CMakeLists.txt @@ -0,0 +1,8 @@ + +# Declare processing module +module( + NAME processing + EXECUTABLES src/hpstr.cxx + DEPENDENCIES + EXTERNAL_DEPENDENCIES ROOT Python +) From 481be1ab707640d80270eb602d7833b42c732669 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:59:14 -0700 Subject: [PATCH 009/314] Add cmake modules. --- cmake/Modules/MacroExtDeps.cmake | 19 ++++ cmake/Modules/MacroModule.cmake | 169 +++++++++++++++++++++++++++++++ cmake/Modules/UsePython.cmake | 2 + cmake/Modules/UseROOT.cmake | 3 + 4 files changed, 193 insertions(+) create mode 100644 cmake/Modules/MacroExtDeps.cmake create mode 100644 cmake/Modules/MacroModule.cmake create mode 100644 cmake/Modules/UsePython.cmake create mode 100644 cmake/Modules/UseROOT.cmake diff --git a/cmake/Modules/MacroExtDeps.cmake b/cmake/Modules/MacroExtDeps.cmake new file mode 100644 index 000000000..435526048 --- /dev/null +++ b/cmake/Modules/MacroExtDeps.cmake @@ -0,0 +1,19 @@ +macro(ext_deps) + + # define options for this function + set(options) + set(multiValueArgs DEPENDENCIES) + + # parse command options + cmake_parse_arguments(EXT_DEPS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + #message("multiValueArgs='${multiValueArgs}'") + #message("EXT_DEPS_DEPENDENCIES='${EXT_DEPS_DEPENDENCIES}'") + + foreach(ext_dep ${EXT_DEPS_DEPENDENCIES}) + #message(${ext_dep}) + #message("including Use${ext_dep}.cmake") + include("Use${ext_dep}") + endforeach() + +endmacro(ext_deps) diff --git a/cmake/Modules/MacroModule.cmake b/cmake/Modules/MacroModule.cmake new file mode 100644 index 000000000..5657eed13 --- /dev/null +++ b/cmake/Modules/MacroModule.cmake @@ -0,0 +1,169 @@ +############################################################################### +# Macro for defining an LDMX code module +# +# The following arguments are accepted by this macro: +# +# NAME - the name of the module (required) +# DEPENDENCIES - list of module dependencies such as 'Event' (optional) +# EXTRA_SOURCES - extra source files produced by this module (optional) +# EXTRA_LINK_LIBRARIES - extra link libraries (optional) +# EXTRA_INCLUDE_DIRS - extra include dirs required by this module (optional) +# EXECUTABLES - source files that should be built into executables (optional) +# +# Only 'NAME' is required as an argument to this macro. All other arguments +# will either be assigned reasonable defaults or will not be used. +# +# The following conventions are assumed: +# +# - The C++ header files are in a directory 'include' with a subdirectory like +# 'include/${MODULE_NAME}' and have the '.h' extension. +# +# - The C++ source files are in a directory 'src' and have the extension '.cxx'. +# +# - Test programs are in the 'test' directory and define an executable 'main' +# function and also have the '.cxx' extension. +# +# The names of the output executables and test programs will be derived from +# the source file names using the file's base name stripped of its extension, +# with underscores replaced by dashes. All test programs and executables will +# be installed into the output 'bin' directory so their names should be unique +# across all modules within the repository. +# +# @author Jeremy McCormick, SLAC +############################################################################### +macro(MODULE) + + # define options for this function + set(options) + set(oneValueArgs NAME) + set(multiValueArgs DEPENDENCIES EXTRA_SOURCES EXTRA_LINK_LIBRARIES EXECUTABLES EXTERNAL_DEPENDENCIES) + + # parse command options + cmake_parse_arguments(MODULE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # set module's include dir + set(MODULE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) + + # set module's source dir + set(MODULE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) + + # print debug info + if(MODULE_DEBUG) + message("MODULE_NAME='${MODULE_NAME}'") + message("MODULE_DEPENDENCIES='${MODULE_DEPENDENCIES}'") + message("MODULE_EXTERNAL_DEPENDENCIES='${MODULE_EXTERNAL_DEPENDENCIES}'") + message("MODULE_INCLUDE_DIR='${MODULE_INCLUDE_DIR}'") + message("MODULE_SOURCE_DIR='${MODULE_SOURCE_DIR}'") + message("MODULE_EXTRA_SOURCES='${MODULE_EXTRA_SOURCES}'") + message("MODULE_EXTRA_LINK_LIBRARIES='${MODULE_EXTRA_LINK_LIBRARIES}'") + message("MODULE_EXECUTABLES='${MODULE_EXECUTABLES}'") + endif() + + # define current project based on module name + project(${MODULE_NAME} CXX) + + # set the local include dir var + set(${MODULE_NAME}_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) + + # export the include dir var to the parent scope + set(${MODULE_NAME}_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include PARENT_SCOPE) + + # add the module include dir to the build + include_directories(${${MODULE_NAME}_INCLUDE_DIR}) + + # add include directories of module dependencies + foreach(dependency ${MODULE_DEPENDENCIES}) + include_directories(${${dependency}_INCLUDE_DIR}) + endforeach() + + # get source and header lists for building the application + file(GLOB sources ${MODULE_SOURCE_DIR}/*.cxx) + file(GLOB headers ${MODULE_INCLUDE_DIR}/include/*/*.h) + + # setup external dependencies + ext_deps(DEPENDENCIES ${MODULE_EXTERNAL_DEPENDENCIES}) + if (EXT_DEP_INCLUDE_DIRS) + include_directories(${EXT_DEP_INCLUDE_DIRS}) + endif() + + # make list of all library dependencies + set(MODULE_LIBRARIES ${MODULE_DEPENDENCIES} ${EXT_DEP_LIBRARIES} ${MODULE_EXTRA_LINK_LIBRARIES}) + if(MODULE_DEBUG) + message("MODULE_LIBRARIES='${MODULE_LIBRARIES}'") + endif() + + # if there are C++ source files then build a shared library + if (sources) + + # add library target + add_library(${MODULE_NAME} SHARED ${sources} ${MODULE_EXTRA_SOURCES}) + + # add link libs + target_link_libraries(${MODULE_NAME} ${MODULE_EXTRA_LINK_LIBRARIES}) + + # install the library + install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + + endif() + + # make list of libraries required by executables and test programs which includes this module's lib + if (sources) + set(MODULE_BIN_LIBRARIES ${MODULE_LIBRARIES} ${MODULE_NAME}) + else() + set(MODULE_BIN_LIBRARIES ${MODULE_LIBRARIES}) + endif() + + if(MODULE_DEBUG) + message("MODULE_BIN_LIBRARIES='${MODULE_BIN_LIBRARIES}'") + endif() + + # find test programs + file(GLOB test_sources ${CMAKE_CURRENT_SOURCE_DIR}/test/*.cxx) + + # setup test programs from all source files in test directory + foreach(test_source ${test_sources}) + get_filename_component(test_program ${test_source} NAME) + string(REPLACE ".cxx" "" test_program ${test_program}) + string(REPLACE "_" "-" test_program ${test_program}) + add_executable(${test_program} ${test_source}) + target_link_libraries(${test_program} ${MODULE_BIN_LIBRARIES}) + install(TARGETS ${test_program} DESTINATION bin) + if(MODULE_DEBUG) + message("building test program: ${test_program}") + endif() + endforeach() + + # setup module executables + foreach(executable_source ${MODULE_EXECUTABLES}) + get_filename_component(executable ${executable_source} NAME) + string(REPLACE ".cxx" "" executable ${executable}) + string(REPLACE "_" "-" executable ${executable}) + if(MODULE_DEBUG) + message("building executable: ${executable}") + endif() + add_executable(${executable} ${executable_source}) + target_link_libraries(${executable} ${MODULE_BIN_LIBRARIES}) + install(TARGETS ${executable} DESTINATION bin) + endforeach() + + # install python scripts + set(PYTHON_INSTALL_DIR lib/python/LDMX/${MODULE_NAME}) + file(GLOB py_scripts "${CMAKE_CURRENT_SOURCE_DIR}/python/[!_]*.py") + if (py_scripts) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/python/__init__.py "# python package") + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/python/__init__.py DESTINATION ${PYTHON_INSTALL_DIR}) + endif() + + # install python programs + foreach(pyscript ${py_scripts}) + install(FILES ${pyscript} DESTINATION ${PYTHON_INSTALL_DIR}) + if(MODULE_DEBUG) + message("installing python script: ${pyscript}") + endif() + endforeach() + + if (MODULE_DEBUG) + message("") + endif() + +endmacro(MODULE) diff --git a/cmake/Modules/UsePython.cmake b/cmake/Modules/UsePython.cmake new file mode 100644 index 000000000..1a59f9d8c --- /dev/null +++ b/cmake/Modules/UsePython.cmake @@ -0,0 +1,2 @@ +set(EXT_DEP_INCLUDE_DIRS ${EXT_DEP_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) +set(EXT_DEP_LIBRARIES ${EXT_DEP_LIBRARIES} ${PYTHON_LIBRARIES}) diff --git a/cmake/Modules/UseROOT.cmake b/cmake/Modules/UseROOT.cmake new file mode 100644 index 000000000..f773ee4c3 --- /dev/null +++ b/cmake/Modules/UseROOT.cmake @@ -0,0 +1,3 @@ +# include ROOT CMake macros and compilation settings +include(${ROOT_USE_FILE}) +set(EXT_DEP_LIBRARIES ${EXT_DEP_LIBRARIES} ${ROOT_LIBRARIES}) From 763f932216e261b5781df3bac2132d044388a0d2 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 29 Oct 2018 09:59:33 -0700 Subject: [PATCH 010/314] Update git ignore. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 259148fa1..2c4af94d3 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ *.exe *.out *.app + +# Byte code +*.pyc From 042cfdd665d4fb9236e2c3fec54513129e1ad8ce Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 31 Oct 2018 23:37:22 -0700 Subject: [PATCH 011/314] Find LCIO headers and libraries. --- CMakeLists.txt | 13 +++++++++++++ cmake/Modules/UseLCIO.cmake | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 cmake/Modules/UseLCIO.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 10d221497..dc0d8888e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,19 @@ # minimum cmake version cmake_minimum_required(VERSION 3.0) +# find the LCIO directory +if (LCIO_DIR) + set(LCIO_INCLUDE_DIR "${LCIO_DIR}/include") + set(LCIO_LIBRARY "${LCIO_DIR}/lib/liblcio.so") + if (NOT EXISTS "${LCIO_DIR}") + message(FATAL_ERROR "Unable to find LCIO library") + endif() + message(STATUS "LCIO dir set to: ${LCIO_DIR}") + message(STATUS "LCIO include dir set to: ${LCIO_INCLUDE_DIR}") + message(STATUS "LCIO library set to: ${LCIO_LIBRARY}") +endif() +find_package(LCIO REQUIRED) + # find Python installation find_package(PythonLibs REQUIRED) message(STATUS "Python lib found at: ${PYTHON_LIBRARIES}") diff --git a/cmake/Modules/UseLCIO.cmake b/cmake/Modules/UseLCIO.cmake new file mode 100644 index 000000000..5550a9d64 --- /dev/null +++ b/cmake/Modules/UseLCIO.cmake @@ -0,0 +1,2 @@ +set(EXT_DEP_INCLUDE_DIRS ${EXT_DEP_INCLUDE_DIRS} ${LCIO_INCLUDE_DIR}) +set(EXT_DEP_LIBRARIES ${EXT_DEP_LIBRARIES} ${LCIO_LIBRARY}) From cbf22cc84ecde37d80946e2fb22c709a5311963c Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 1 Nov 2018 00:04:34 -0700 Subject: [PATCH 012/314] Add LCIO as an external dependency. --- processing/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/CMakeLists.txt b/processing/CMakeLists.txt index de4fe581e..9985177a6 100644 --- a/processing/CMakeLists.txt +++ b/processing/CMakeLists.txt @@ -4,5 +4,5 @@ module( NAME processing EXECUTABLES src/hpstr.cxx DEPENDENCIES - EXTERNAL_DEPENDENCIES ROOT Python + EXTERNAL_DEPENDENCIES ROOT Python LCIO ) From a60efb05ac9c28597fe03f4f9022ee08681854e8 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 1 Nov 2018 00:05:32 -0700 Subject: [PATCH 013/314] Use an LCIO reader. --- processing/include/Process.h | 7 +++++++ processing/src/Process.cxx | 39 +++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/processing/include/Process.h b/processing/include/Process.h index 491f654b6..1e8bc08a2 100644 --- a/processing/include/Process.h +++ b/processing/include/Process.h @@ -14,6 +14,13 @@ #include #include +//----------// +// LCIO // +//----------// +#include +#include +#include + //----------// // ROOT // //----------// diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 4d1e3821f..ea74b7048 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -17,22 +17,25 @@ void Process::run() { if (input_files_.empty()) throw std::runtime_error("Please specify files to process."); - //data_reader = new DataRead(); - //TrackerEvent event; + // Instantiate the LCIO file reader + IO::LCReader* lc_reader = IOIMPL::LCFactory::getInstance()->createLCReader(); + + // Create an object used to store all of the event information of the + // current event. + EVENT::LCEvent* event{nullptr}; int cfile = 0; for (auto ifile : input_files_) { - // Open the input file. If the input file can't be opened, exit - // the application. - //if (!data_reader->open(ifile.c_str(), false)) - // throw std::runtime_error("Error! File " + ifile + " cannot be opened."); + // Open the input file. If the input file can't be opened, throw + // an exeception. + lc_reader->open(ifile); - std::cout << "---- [ svt-qa ][ Process ]: Processing file " + std::cout << "---- [ hpstr ][ Process ]: Processing file " << ifile << std::endl; // Open the output file where all histograms will be stored. - TFile* ofile = new TFile(output_files_[cfile].c_str(), "RECREATE"); + //TFile* ofile = new TFile(output_files_[cfile].c_str(), "RECREATE"); // first, notify everyone that we are starting for (auto module : sequence_) { @@ -40,26 +43,30 @@ void Process::run() { } - //while (data_reader->next(&event)) { - // for (auto module : sequence_) { - // module->process(&event); - // } - //} + while ((event = lc_reader->readNextEvent()) != 0) { + //std::cout << "--- [ hpstr ][ Process ]: Event: " << std::endl; + for (auto module : sequence_) { + module->process(event); + } + } ++cfile; for (auto module : sequence_) { module->finalize(); } - if (ofile) { + /*if (ofile) { ofile->Write(); delete ofile; ofile = nullptr; - } + }*/ + + // Close the LCIO file that was being processed + lc_reader->close(); } } catch (std::exception& e) { - std::cerr << "---- [ svt-qa ][ Process ]: Error! " << e.what() << std::endl; + std::cerr << "---- [ hpstr ][ Process ]: Error! " << e.what() << std::endl; } } From d9e55f345e68e1762b1a31ba9cad41ff5a2edacb Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 1 Nov 2018 00:06:11 -0700 Subject: [PATCH 014/314] Process and LCIO event. --- processing/include/Processor.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/processing/include/Processor.h b/processing/include/Processor.h index 174d5be76..7a65ad0ac 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -12,10 +12,11 @@ //----------------// #include -//---------// -// DAQ // -//---------// -//#include "TrackerEvent.h" +//----------// +// LCIO // +//----------// +#include + // Forward declarations class Process; @@ -54,7 +55,7 @@ class Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - //virtual void process(TrackerEvent* event) = 0; + virtual void process(EVENT::LCEvent* event) = 0; /** * Callback for the Processor to take any necessary From 63e05359057cea0449abc12ce4f021146f38f34a Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:25:54 -0800 Subject: [PATCH 015/314] Class defining methods used to access event information and data collections. --- event/include/Event.h | 47 +++++++++++++++++++++++++++++++++++++++++++ event/src/Event.cxx | 22 ++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 event/include/Event.h create mode 100644 event/src/Event.cxx diff --git a/event/include/Event.h b/event/include/Event.h new file mode 100644 index 000000000..8bb2350b5 --- /dev/null +++ b/event/include/Event.h @@ -0,0 +1,47 @@ +/** + * @file Event.h + * @brief Class defining methods used to access event information and data + * collections. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __EVENT_H__ +#define __EVENT_H__ + +//----------// +// ROOT // +//----------// +#include +#include + +class Event { + + public: + + /** Constructor */ + Event(); + + /** Destructor */ + ~Event(); + + /** + * Add a collection (TClonesArray) of objects to the event. + * + * @param name Name of the collection + * @param collection The TClonesArray containing the object. + */ + void addCollection(const std::string name, TClonesArray* collection); + + /** @return The ROOT tree containing the event. */ + TTree* getTree() { return tree_; } + + private: + + /** The ROOT tree containing the event. */ + TTree* tree_{nullptr}; + +}; // Event + +#endif // __EVENT_H__ + + diff --git a/event/src/Event.cxx b/event/src/Event.cxx new file mode 100644 index 000000000..bfe389a25 --- /dev/null +++ b/event/src/Event.cxx @@ -0,0 +1,22 @@ +/** + * @file Event.cxx + * @brief Class defining methods used to access event information and data + * collections. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "Event.h" + +Event::Event() { + + // Create the tree + tree_ = new TTree("HPS_Event", "HPS event tree"); +} + +Event::~Event() {} + +void Event::addCollection(const std::string name, TClonesArray* collection) { + + // Add a branch with the given name to the event tree. + tree_->Branch(name.c_str(), collection, 1000000, 3); +} From a29f4239dbdc38bf5036a6a36b8728ec9cfc1320 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:26:14 -0800 Subject: [PATCH 016/314] Add the event directory to the build. --- event/CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 event/CMakeLists.txt diff --git a/event/CMakeLists.txt b/event/CMakeLists.txt new file mode 100644 index 000000000..235a92e85 --- /dev/null +++ b/event/CMakeLists.txt @@ -0,0 +1,7 @@ + +# Declare processing module +module( + NAME event + DEPENDENCIES + EXTERNAL_DEPENDENCIES ROOT +) From 78e4876af488c821613736d189ff5896bc9f4387 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:34:16 -0800 Subject: [PATCH 017/314] Class for managing IO files. --- processing/include/EventFile.h | 75 ++++++++++++++++++++++++++++++++++ processing/src/EventFile.cxx | 50 +++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 processing/include/EventFile.h create mode 100644 processing/src/EventFile.cxx diff --git a/processing/include/EventFile.h b/processing/include/EventFile.h new file mode 100644 index 000000000..9efe04953 --- /dev/null +++ b/processing/include/EventFile.h @@ -0,0 +1,75 @@ +/** + * @file EventFile.h + * @brief Class for managing io files. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __EVENT_FILE_H__ +#define __EVENT_FILE_H__ + +//----------// +// ROOT // +//----------// +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include + +//-----------// +// hpstr // +//-----------// +#include "Event.h" + +class EventFile { + + public: + + /** Constructor */ + EventFile(const std::string ifilename, const std::string ofilename); + + /** Destructor */ + ~EventFile(); + + /** + * Load the next event in the file. + * + * @return true if an event was loaded successfully, false otherwise + */ + bool nextEvent(); + + /** + * Setup the event object that will be used by this file. + * + * @param event The Event container. + */ + void setupEvent(Event* event); + + /** + * Close the file, writing the tree to disk if creating an output file. + */ + void close(); + + private: + + /** The ROOT file to which event data will be written to. */ + TFile* ofile_{nullptr}; + + /** Object used to build the HPS event model. */ + Event* event_{nullptr}; + + /** Object used to load all of current LCIO event information. */ + EVENT::LCEvent* lc_event_{nullptr}; + + /** LCIO reader */ + IO::LCReader* lc_reader_{IOIMPL::LCFactory::getInstance()->createLCReader()}; + + int entry_{0}; + +}; // EventFile + +#endif // __EVENT_FILE_H__ diff --git a/processing/src/EventFile.cxx b/processing/src/EventFile.cxx new file mode 100644 index 000000000..4c6f05acd --- /dev/null +++ b/processing/src/EventFile.cxx @@ -0,0 +1,50 @@ +/** + * @file EventFile.cxx + * @brief Class for managing IO files. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "EventFile.h" + +EventFile::EventFile(const std::string ifilename, const std::string ofilename) { + + // Open the input LCIO file. If the input file can't be opened, throw an + // exception. + lc_reader_->open(ifilename); + + // Open the output ROOT file + ofile_ = new TFile(ofilename.c_str(), "recreate"); +} + +EventFile::~EventFile() {} + +bool EventFile::nextEvent() { + + // Close out the previous event before moving on. + if (entry_ > 0) { + event_->getTree()->Fill(); + } + + // Read the next event. If it doesn't exist, stop processing events. + if ((lc_event_ = lc_reader_->readNextEvent()) == 0) return false; + + ++entry_; + return true; +} + +void EventFile::setupEvent(Event* event) { + event_ = event; + entry_ = 0; +} + +void EventFile::close() { + + // Close the LCIO file that was being processed + lc_reader_->close(); + + // Write the ROOT tree to disk + event_->getTree()->Write(); + + // Close the ROOT file + ofile_->Close(); +} From 6a9905ffed52b36e9660826184f663221a912faf Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:34:59 -0800 Subject: [PATCH 018/314] Add the event module to the build. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc0d8888e..dea2a4617 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ include(MacroExtDeps) # declare list of modules with correct dependency order #set(MODULES Event Framework DetDescr Tools EventProc SimCore SimPlugins Biasing SimApplication Configuration Detectors Ecal EventDisplay) -set(MODULES processing) +set(MODULES event processing) # build each module in the list foreach(module ${MODULES}) From 1ff46079c837dda76f39de01288247620c14f68a Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:37:51 -0800 Subject: [PATCH 019/314] Move processing of LCIO files to EventFile. --- processing/src/Process.cxx | 41 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index ea74b7048..c1ec1b779 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -17,52 +17,47 @@ void Process::run() { if (input_files_.empty()) throw std::runtime_error("Please specify files to process."); - // Instantiate the LCIO file reader - IO::LCReader* lc_reader = IOIMPL::LCFactory::getInstance()->createLCReader(); - - // Create an object used to store all of the event information of the - // current event. - EVENT::LCEvent* event{nullptr}; + // Create an object used to manage the input and output files. + Event event; int cfile = 0; for (auto ifile : input_files_) { - // Open the input file. If the input file can't be opened, throw - // an exeception. - lc_reader->open(ifile); - std::cout << "---- [ hpstr ][ Process ]: Processing file " << ifile << std::endl; - // Open the output file where all histograms will be stored. - //TFile* ofile = new TFile(output_files_[cfile].c_str(), "RECREATE"); + // Open the output file if an output file path has been specified. + EventFile* file{nullptr}; + if (!output_files_.empty()) { + file = new EventFile(ifile, output_files_[cfile]); + file->setupEvent(&event); + } // first, notify everyone that we are starting for (auto module : sequence_) { module->initialize(); } - - while ((event = lc_reader->readNextEvent()) != 0) { + // Process all events. + while (file->nextEvent()) { //std::cout << "--- [ hpstr ][ Process ]: Event: " << std::endl; for (auto module : sequence_) { - module->process(event); + module->process(&event); } } ++cfile; - + + // Finalize all modules. for (auto module : sequence_) { module->finalize(); } - /*if (ofile) { - ofile->Write(); - delete ofile; - ofile = nullptr; - }*/ + if (file) { + file->close(); + delete file; + file = nullptr; + } - // Close the LCIO file that was being processed - lc_reader->close(); } } catch (std::exception& e) { From 3b3f9b0c8e89e241ff2102fc9d99e909b49627c4 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:38:10 -0800 Subject: [PATCH 020/314] Move processing of LCIO files to EventFile. --- processing/include/Process.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/processing/include/Process.h b/processing/include/Process.h index 1e8bc08a2..2119b2168 100644 --- a/processing/include/Process.h +++ b/processing/include/Process.h @@ -14,22 +14,16 @@ #include #include -//----------// -// LCIO // -//----------// -#include -#include -#include - //----------// // ROOT // //----------// #include -//------------// -// svt-qa // -//------------// +//-----------// +// hpstr // +//-----------// #include "Processor.h" +#include "EventFile.h" class Process { From ecd200a7dcfec0d8768609691a43b51fd9deff89 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:38:40 -0800 Subject: [PATCH 021/314] Process an Event object instead of an LCEvent. --- processing/include/Processor.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/processing/include/Processor.h b/processing/include/Processor.h index 7a65ad0ac..baac2c427 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -12,11 +12,10 @@ //----------------// #include -//----------// -// LCIO // -//----------// -#include - +//-----------// +// hpstr // +//-----------// +#include "Event.h" // Forward declarations class Process; @@ -55,7 +54,7 @@ class Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(EVENT::LCEvent* event) = 0; + virtual void process(Event* event) = 0; /** * Callback for the Processor to take any necessary From e5c6a0abf71f377c16fe67983ae71e3e5b10596a Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 28 Nov 2018 14:39:02 -0800 Subject: [PATCH 022/314] Add the event module as a dependency. --- processing/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/CMakeLists.txt b/processing/CMakeLists.txt index 9985177a6..9ca88da7f 100644 --- a/processing/CMakeLists.txt +++ b/processing/CMakeLists.txt @@ -3,6 +3,6 @@ module( NAME processing EXECUTABLES src/hpstr.cxx - DEPENDENCIES + DEPENDENCIES event EXTERNAL_DEPENDENCIES ROOT Python LCIO ) From 4e6aa01b78427200c17620e73d24223c980d313d Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Sat, 1 Dec 2018 15:02:18 -0800 Subject: [PATCH 023/314] Allow a user to specify a max number of events. --- processing/src/Process.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index c1ec1b779..cf53810db 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -39,11 +39,12 @@ void Process::run() { } // Process all events. - while (file->nextEvent()) { - //std::cout << "--- [ hpstr ][ Process ]: Event: " << std::endl; + while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { + std::cout << "--- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; for (auto module : sequence_) { module->process(&event); } + ++n_events_processed; } ++cfile; From b890b7f998e910d04d1ad2f0513d081405110f64 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Tue, 4 Dec 2018 22:34:50 -0800 Subject: [PATCH 024/314] Add method to set LCEvent. Only add a collection to the event if it hasn't been added yet. --- event/include/Event.h | 26 ++++++++++++++++++++++++++ event/src/Event.cxx | 15 ++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/event/include/Event.h b/event/include/Event.h index 8bb2350b5..d21969507 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -8,6 +8,12 @@ #ifndef __EVENT_H__ #define __EVENT_H__ +//----------// +// LCIO // +//----------// +#include +#include + //----------// // ROOT // //----------// @@ -32,13 +38,33 @@ class Event { */ void addCollection(const std::string name, TClonesArray* collection); + + /** + * Clear all of the collections in the event + */ + void Clear(); + /** @return The ROOT tree containing the event. */ TTree* getTree() { return tree_; } + /** Set the LCIO event. */ + void setLCEvent(EVENT::LCEvent* lc_event) { lc_event_ = lc_event; }; + + /** Get the LCIO event. */ + EVENT::LCCollection* getLCCollection(std::string name) { + return static_cast(lc_event_->getCollection(name)); + }; + private: /** The ROOT tree containing the event. */ TTree* tree_{nullptr}; + + /** Object used to load all of current LCIO event information. */ + EVENT::LCEvent* lc_event_{nullptr}; + + /** Container with all TClonesArray collections. */ + std::map collections_; }; // Event diff --git a/event/src/Event.cxx b/event/src/Event.cxx index bfe389a25..b4ef98647 100644 --- a/event/src/Event.cxx +++ b/event/src/Event.cxx @@ -17,6 +17,19 @@ Event::~Event() {} void Event::addCollection(const std::string name, TClonesArray* collection) { + // Check if the collection has been added + if (collections_.find(name) != collections_.end()) return; + // Add a branch with the given name to the event tree. - tree_->Branch(name.c_str(), collection, 1000000, 3); + tree_->Branch(name.c_str(), collection, 1000000, 3); + + // Kepp track of which events were added to the event + collections_[name] = collection; +} + +void Event::Clear() { + + for (auto& collection : collections_) { + collection.second->Clear("C"); + } } From efd0045a9bf865e1ed477dde684cd1512ee7dd59 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Tue, 4 Dec 2018 22:35:29 -0800 Subject: [PATCH 025/314] Set the LCEvent. --- processing/src/EventFile.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/processing/src/EventFile.cxx b/processing/src/EventFile.cxx index 4c6f05acd..ed6549509 100644 --- a/processing/src/EventFile.cxx +++ b/processing/src/EventFile.cxx @@ -27,6 +27,8 @@ bool EventFile::nextEvent() { // Read the next event. If it doesn't exist, stop processing events. if ((lc_event_ = lc_reader_->readNextEvent()) == 0) return false; + + event_->setLCEvent(lc_event_); ++entry_; return true; From dcaad51aa42b99a9bd8ede20ac56d897637f0702 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Tue, 4 Dec 2018 22:36:04 -0800 Subject: [PATCH 026/314] Clear the event after processing all modules. --- processing/src/Process.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index cf53810db..23ef8076b 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -41,6 +41,7 @@ void Process::run() { // Process all events. while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { std::cout << "--- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; + event.Clear(); for (auto module : sequence_) { module->process(&event); } From 622eb5feccdec152ba766d4a20d5821d41556270 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 6 Dec 2018 12:25:19 -0800 Subject: [PATCH 027/314] Class used to encapsulate tracker hit information. --- event/include/TrackerHit.h | 104 +++++++++++++++++++++++++++++++++++++ event/src/TrackerHit.cxx | 45 ++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 event/include/TrackerHit.h create mode 100644 event/src/TrackerHit.cxx diff --git a/event/include/TrackerHit.h b/event/include/TrackerHit.h new file mode 100644 index 000000000..11590fa6a --- /dev/null +++ b/event/include/TrackerHit.h @@ -0,0 +1,104 @@ +/** + * @file TrackerHit.h + * @brief Class used to encapsulate tracker hit information + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _TRACKER_HIT_H_ +#define _TRACKER_HIT_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include +#include + +class TrackerHit : public TObject { + + public: + + /** Constructor */ + TrackerHit(); + + /** Destructor */ + virtual ~TrackerHit(); + + /** Reset the Hit object. */ + void Clear(Option_t *option=""); + + /** + * Set the layer associated with this hit. + * + * @param layer The layer associated with this hit. + */ + void setLayer(const int layer){ this->layer = layer; }; + + /** + * Set the hit position. + * + * @param position The hit position. + */ + void setPosition(const double* position); + + /** @return The hit position. */ + std::vector getPosition() const; + + /** + * Set the covariance matrix. + * + * @param cov The covariance matrix. + */ + void setCovarianceMatrix(std::vector cov); + + /** @return The convariance matrix. */ + std::vector getCovarianceMatrix() const; + + /** + * Set the hit time. + * + * @param time The hit time. + */ + void setTime(const double time) { this->time = time; }; + + /** @return The layer associated with this hit. */ + double getLayer() const { return layer; }; + + + /** @return The hit time. */ + double getTime() const { return time; }; + + ClassDef(TrackerHit, 1); + + private: + + /** The x position of the hit. */ + double x{-999}; + + /** The x position of the hit. */ + double y{-999}; + + /** The x position of the hit. */ + double z{-999}; + + /** Components of the covariance matrix. */ + double cxx{0}; + double cxy{0}; + double cxz{0}; + double cyy{0}; + double cyz{0}; + double czz{0}; + + /** The hit time. */ + double time{-999}; + + /** The hit layer. */ + int layer{0}; + +}; // TrackerHit + +#endif // _TRACKER_HIT_H_ diff --git a/event/src/TrackerHit.cxx b/event/src/TrackerHit.cxx new file mode 100644 index 000000000..bed04ef2a --- /dev/null +++ b/event/src/TrackerHit.cxx @@ -0,0 +1,45 @@ +/** + * @file TrackerHit.cxx + * @brief Class used to encapsulate tracker hit information + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "TrackerHit.h" + +ClassImp(TrackerHit) + +TrackerHit::TrackerHit() + : TObject() { +} + +TrackerHit::~TrackerHit() { + Clear(); +} + +void TrackerHit::Clear(Option_t* /* options */) { + TObject::Clear(); +} + +void TrackerHit::setPosition(const double* position) { + x = position[0]; + y = position[1]; + z = position[2]; +} + +std::vector TrackerHit::getPosition() const { + return { x, y, z }; +} + + +void TrackerHit::setCovarianceMatrix(const std::vector covariance_matrix) { + cxx = covariance_matrix[0]; + cxy = covariance_matrix[1]; + cxz = covariance_matrix[2]; + cyy = covariance_matrix[3]; + cyz = covariance_matrix[4]; + czz = covariance_matrix[5]; +} + +std::vector TrackerHit::getCovarianceMatrix() const { + return { cxx, cxy, cxz, cyy, cyz, czz }; +} From b0bf3b7baaf80826520e8103d98eb59cc3ff81c1 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 6 Dec 2018 12:26:53 -0800 Subject: [PATCH 028/314] Create a ROOT dictionary when compiling. --- event/CMakeLists.txt | 6 ++++-- event/include/EventDef.h | 4 ++++ event/include/EventLinkDef.h | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 event/include/EventDef.h create mode 100644 event/include/EventLinkDef.h diff --git a/event/CMakeLists.txt b/event/CMakeLists.txt index 235a92e85..f519a441d 100644 --- a/event/CMakeLists.txt +++ b/event/CMakeLists.txt @@ -2,6 +2,8 @@ # Declare processing module module( NAME event - DEPENDENCIES - EXTERNAL_DEPENDENCIES ROOT + EXTRA_SOURCES EventDict.cxx + EXTERNAL_DEPENDENCIES ROOT LCIO ) + +root_generate_dictionary(EventDict ${event_INCLUDE_DIR}/EventDef.h MODULE ${PROJECT_NAME} LINKDEF ${event_INCLUDE_DIR}/EventLinkDef.h) diff --git a/event/include/EventDef.h b/event/include/EventDef.h new file mode 100644 index 000000000..3475894f7 --- /dev/null +++ b/event/include/EventDef.h @@ -0,0 +1,4 @@ + +#include "Event.h" +#include "Track.h" +#include "TrackerHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h new file mode 100644 index 000000000..fdfa7f2ed --- /dev/null +++ b/event/include/EventLinkDef.h @@ -0,0 +1,12 @@ +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ nestedclasses; + +#pragma link C++ class Track+; +#pragma link C++ class TrackerHit+; + +#endif From c1f88cbc4060cf9fea2aaa1c2d8985d3e3ea984b Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 6 Dec 2018 17:31:02 -0800 Subject: [PATCH 029/314] Class used to encapsulate track information. --- event/include/Track.h | 289 ++++++++++++++++++++++++++++++++++++++++++ event/src/Track.cxx | 59 +++++++++ 2 files changed, 348 insertions(+) create mode 100644 event/include/Track.h create mode 100644 event/src/Track.cxx diff --git a/event/include/Track.h b/event/include/Track.h new file mode 100644 index 000000000..04f432a66 --- /dev/null +++ b/event/include/Track.h @@ -0,0 +1,289 @@ +/** + * @file Track.h + * @brief Class used to encapsulate track information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _TRACK_H_ +#define _TRACK_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include + +//----------// +// ROOT // +//----------// +#include +#include +#include +#include + +//----------// +// hpstr // +//----------// +#include "TrackerHit.h" + +class Track : public TObject { + + public: + + /** Constructor */ + Track(); + + /** Destructor */ + ~Track(); + + /** Reset the Track object */ + void Clear(Option_t *option=""); + + /** + * Add a reference to an TrackerHit. + * + * @param hit : A TrackerHit object + */ + void addHit(TrackerHit* hit); + + /** + * Set the track parameters. + * + * @param d0 Distance of closest approach to the reference point. + * @param phi0 The azimuthal angle of the momentum at the distance of + * closest approach. + * @param omega The curvature of the track. + * @param tan_lambda The slope of the track in the SY plane. + * @param z0 The y position of the track at the distance of closest + * approach. + */ + void setTrackParameters(const double d0, + const double phi0, + const double omega, + const double tan_lambda, + const double z0); + + /** @return The track parameters. */ + std::vector getTrackParameters(); + + /** + * Set the chi^2 of the fit to the track. + * + * @param chi2 The chi^2 of the fit to the track. + */ + void setChi2(const double chi2) { chi2_ = chi2; }; + + /** @return the chi^2 of the fit to the track. */ + double getChi2() const { return chi2_; }; + + /** + * Set the isolation variable of the given layer. + * + * @param layer Layer number associated with the given isolation value. + * @param isolation The isolation variable. + */ + void setIsolation(const int layer, const double isolation) { isolation_[layer] = isolation; }; + + + /** + * Get the isolation value of the given layer. + * + * @param layer The SVT layer of interest. + * @return The isolation value of the given layer. + */ + double getIsolation(const int layer) const { return isolation_[layer]; }; + + + /** @param track_time The track time. */ + void setTrackTime(const double track_time) { track_time_ = track_time; }; + + /** + * Get the time of the track. + * + * @return The track time. + */ + double getTrackTime() const { return track_time_; }; + + /** + * The the volume (Top/Bottom) that the track is located in. + * + * @param track_volume The track volume. + */ + void setTrackVolume(const int track_volume) { track_volume_ = track_volume; }; + + /** + * Set the HpsParticle associated with this track. This can be used to + * retrieve additional track properties such as the momentum and charge. + * + * @param fs_particle : Final state HpsParticle associated with this track + */ + //void setParticle(HpsParticle* fs_particle) { this->fs_particle = (TObject*) fs_particle; }; + + /** + * Set the extrapolated track position at the Ecal face. The + * extrapolation is assumed to use the full 3D field map. + * + * @parm position The extrapolated track position at the Ecal + */ + void setPositionAtEcal(const double* position); + + /** @return Extrapolated track position at Ecal face. */ + std::vector getPositionAtEcal(); + + /** + * Set the track type. For more details, see {@link StrategyType} and + * {@link TrackType}. + * + * @param type The track type. + */ + void setType(const int type) { this->type = type; }; + + /** @return The track type. */ + int getType() const { return type; }; + + + /** + * Get the charge of a the track. + * + * @return The charge associated of the track. + */ + int getCharge(); + + /** + * Get the track momentum. + * + * @return The track momentum. + */ + std::vector getMomentum(); + + /** + * Set the lambda kink of the given layer. + * + * @param layer Layer number associated with the given lambda kink. + * @param lambda_kink The lambda kink value. + */ + void setLambdaKink(const int layer, const double lambda_kink) { lambda_kinks_[layer] = lambda_kink; } + + /** + * Get the lambda kink value of the given layer. + * + * @param layer The SVT layer of interest. + * @return The lambda kink value of the given layer. + */ + double getLambdaKink(const int layer) const { return lambda_kinks_[layer]; } + + /** + * Set the phi kink of the given layer. + * + * @param layer Layer number associated with the given phi kink. + * @param phi_kink The phi kink value. + */ + void setPhiKink(const int layer, const double phi_kink) { phi_kinks_[layer] = phi_kink; } + + /** + * Get the phi kink value of the given layer. + * + * @param layer The SVT layer of interest. + * @return The phi kink value of the given layer. + */ + double getPhiKink(const int layer) const { return phi_kinks_[layer]; } + + /** + * Get an array of references to the hits associated with this track. + * + * @return A reference to the hits associated with this track. + */ + TRefArray* getSvtHits() const { return tracker_hits_; }; + + /** + * Get the {@link HpsParticle} associated with this track. + * + * @return The {@link HpsParticle} associated with this track. + */ + //HpsParticle* getParticle() const { return (HpsParticle*) this->fs_particle.GetObject(); }; + + /** + * @returns True if the track is in the top SVT volume, false otherwise. + */ + bool isTopTrack() const { return track_volume_ ? false : true; }; + + /** + * @return True if the track is in the bottom SVT volume, false otherwise. + */ + bool isBottomTrack() const { return track_volume_ ? true : false; }; + + private: + + /** Reference to the 3D hits associated with this track. */ + TRefArray* tracker_hits_{new TRefArray{}}; + + /** Reference to the reconstructed particle associated with this track. */ + //TRef fs_particle; + + /** Array used to store the isolation variables for each of the sensor layers. */ + double isolation_[12]; + + /** The number of 3D hits associated with this track. */ + int n_hits_{0}; + + /** The volume to which this track belongs to. */ + int track_volume_{-999}; + + /** The track type. */ + int type{-999}; + + /** The distance of closest approach to the reference point. */ + double d0_{-999}; + + /** + * The azimuthal angle of the momentum at the position of closest + * approach to the reference point. + */ + double phi0_{-999}; + + /** + * The track curvature. The curvature is positive (negative) if the particle has a + * positive (negative) charge. + */ + double omega_{-999}; + + /** + * The slope of the track in the SY plane where S is the arc length of + * the helix in the xz plane. + */ + double tan_lambda_{-999}; + + /** + * The y position of the track at the distance of closest approach + * in the xz plane. + */ + double z0_{-999}; + + /** The chi^2 of the track fit. */ + double chi2_{-999}; + + /** + * The time of the track. This is currently the average time of all + * hits composing the track. + */ + double track_time_{-999}; + + /** The x position of the extrapolated track at the Ecal face. */ + double x_at_ecal_{-999}; + + /** The y position of the extrapolated track at the Ecal face. */ + double y_at_ecal_{-999}; + + /** The z position of the extrapolated track at the Ecal face. */ + double z_at_ecal_{-999}; + + /** Array used to store the lambda kinks for each of the sensor layers. */ + double lambda_kinks_[12]; + + /** Array used to store the phi kinks for each of the sensor layers. */ + double phi_kinks_[12]; + + ClassDef(Track, 1); +}; // Track + +#endif // __TRACK_H__ diff --git a/event/src/Track.cxx b/event/src/Track.cxx new file mode 100644 index 000000000..48a1ed26b --- /dev/null +++ b/event/src/Track.cxx @@ -0,0 +1,59 @@ +/** + * @file Track.h + * @brief Class used to encapsulate track information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "Track.h" + +ClassImp(Track) + +Track::Track() + : TObject() { +} + +Track::~Track() { + Clear(); + delete tracker_hits_; +} + +void Track::Clear(Option_t* /* option */) { + TObject::Clear(); + tracker_hits_->Delete(); + memset(isolation_, 0, sizeof(isolation_)); + n_hits_ = 0; +} + +void Track::setTrackParameters(double d0, double phi0, double omega, + double tan_lambda, double z0) { + d0_ = d0; + phi0_ = phi0; + omega_ = omega; + tan_lambda_ = tan_lambda; + z0_ = z0; +} + +std::vector Track::getTrackParameters() { return { d0_, phi0_, omega_, tan_lambda_, z0_ }; } + +void Track::setPositionAtEcal(const double* position) { + x_at_ecal_ = position[0]; + y_at_ecal_ = position[1]; + z_at_ecal_ = position[2]; +} + +std::vector Track::getPositionAtEcal() { return { x_at_ecal_, y_at_ecal_, z_at_ecal_ }; } + +//int Track::getCharge() { +// if (fs_particle == NULL) return 9999; +// return ((HpsParticle*) this->fs_particle.GetObject())->getCharge(); +//} + +//std::vector Track::getMomentum() { +// if (fs_particle == NULL) return {0, 0, 0}; +// return ((HpsParticle*) this->fs_particle.GetObject())->getMomentum(); +//} + +void Track::addHit(TrackerHit* hit) { + ++n_hits_; + tracker_hits_->Add(static_cast(hit)); +} From b46e89f93059d204289f320c9b39b79778cad620 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 6 Dec 2018 17:31:32 -0800 Subject: [PATCH 030/314] Header with collection names. --- event/include/Collections.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 event/include/Collections.h diff --git a/event/include/Collections.h b/event/include/Collections.h new file mode 100644 index 000000000..14af2f9e7 --- /dev/null +++ b/event/include/Collections.h @@ -0,0 +1,32 @@ +/** + * @file Collection.h + * @brief List of collection names. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _COLLECTIONS_H_ +#define _COLLECTIONS_H_ + +namespace Collections { + + /** Name of the tracks collection. */ + constexpr const char* HPS_TRACKS{"GBLTracks"}; + + /** Name of the tracker hits collection. */ + constexpr const char* HPS_TRACKER_HITS{"RotatedHelicalTrackHits"}; + + /** The name of the collection containing GBL kink data GenericObjects */ + constexpr const char* KINK_DATA{"GBLKinkData"}; + + /** Name of the collection containing Track to GBLKinkData LCRelations. */ + constexpr const char* KINK_DATA_REL{"GBLKinkDataRelations"}; + + /** Name of the collection of TrackData GenericObjects */ + constexpr const char* TRACK_DATA{"TrackData"}; + + /** Name of the collection containing Track to TrackData LCRelations */ + constexpr const char* TRACK_DATA_REL{"TrackDataRelations"}; + +} + +#endif // _COLLECTION_H_ From ffe0a7f9a43c62d8ea6eafef9842ac88ac50b919 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 6 Dec 2018 17:33:08 -0800 Subject: [PATCH 031/314] Processor used to translate SVT data in LCIO format to DST format. --- CMakeLists.txt | 2 +- processors/CMakeLists.txt | 7 + processors/include/SvtDataProcessor.h | 82 +++++++++++ processors/src/SvtDataProcessor.cxx | 197 ++++++++++++++++++++++++++ 4 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 processors/CMakeLists.txt create mode 100644 processors/include/SvtDataProcessor.h create mode 100644 processors/src/SvtDataProcessor.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index dea2a4617..ac6e4de85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ include(MacroExtDeps) # declare list of modules with correct dependency order #set(MODULES Event Framework DetDescr Tools EventProc SimCore SimPlugins Biasing SimApplication Configuration Detectors Ecal EventDisplay) -set(MODULES event processing) +set(MODULES event processing processors) # build each module in the list foreach(module ${MODULES}) diff --git a/processors/CMakeLists.txt b/processors/CMakeLists.txt new file mode 100644 index 000000000..a4f264357 --- /dev/null +++ b/processors/CMakeLists.txt @@ -0,0 +1,7 @@ + +# Declare processors module +module( + NAME processors + DEPENDENCIES event processing + EXTERNAL_DEPENDENCIES ROOT LCIO +) diff --git a/processors/include/SvtDataProcessor.h b/processors/include/SvtDataProcessor.h new file mode 100644 index 000000000..f9f27710e --- /dev/null +++ b/processors/include/SvtDataProcessor.h @@ -0,0 +1,82 @@ +/** + * + */ + +#ifndef __SVT_DATA_PROCESSOR_H__ +#define __SVT_DATA_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "Track.h" +#include "TrackerHit.h" + +class SvtDataProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + SvtDataProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~SvtDataProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual void process(Event* event); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Container to hold all TrackerHit objects. */ + TClonesArray* hits_{nullptr}; + + /** Container to hold all Track objects. */ + TClonesArray* tracks_{nullptr}; + + +}; // SvtDataProcessor + +#endif // __SVT_DATA_PROCESSOR_H__ diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx new file mode 100644 index 000000000..aa8fd18f0 --- /dev/null +++ b/processors/src/SvtDataProcessor.cxx @@ -0,0 +1,197 @@ + +#include "SvtDataProcessor.h" + +SvtDataProcessor::SvtDataProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +SvtDataProcessor::~SvtDataProcessor() { +} + +void SvtDataProcessor::initialize() { + + tracks_ = new TClonesArray("Track", 100000); + hits_ = new TClonesArray("TrackerHit", 100000); +} + +void SvtDataProcessor::process(Event* event) { + + + // Get the collection of 3D hits from the LCIO event. If no such collection + // exist, a DataNotAvailableException is thrown + EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::HPS_TRACKER_HITS); + + // Create a map from an LCIO TrackerHit to a SvtHit. This will be used when + // assigning references to a track + // TODO: Use an unordered map for faster access + std::map hit_map; + + // Loop over all of the 3D hits in the LCIO event and add them to the + // HPS event + for (int ihit = 0; ihit < tracker_hits->getNumberOfElements(); ++ihit) { + + // Get a 3D hit from the list of hits + EVENT::TrackerHit* lc_tracker_hit = static_cast(tracker_hits->getElementAt(ihit)); + + // Add a tracker hit to the event + TrackerHit* tracker_hit = static_cast(hits_->ConstructedAt(ihit)); + + // Rotate the position of the LCIO TrackerHit and set the position of + // the TrackerHit + double hit_position[3] = { + lc_tracker_hit->getPosition()[1], + lc_tracker_hit->getPosition()[2], + lc_tracker_hit->getPosition()[0] + }; + tracker_hit->setPosition(hit_position); + + // Set the covariance matrix of the SvtHit + tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); + + // Set the time of the SvtHit + tracker_hit->setTime(lc_tracker_hit->getTime()); + + // Map the TrackerHit object to the corresponding SvtHit object. This + // will be used later when setting references for hits on tracks. + hit_map[lc_tracker_hit] = tracker_hit; + + } + + // Add the hit collection to the event + event->addCollection("TrackerHits", hits_); + + // Get all track collections from the event + EVENT::LCCollection* tracks = event->getLCCollection(Collections::HPS_TRACKS); + + + // Loop over all the LCIO Tracks and add them to the HPS event. + for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { + + // Get a LCIO Track from the LCIO event + EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); + + // Add a track to the event + Track* track = static_cast(tracks_->ConstructedAt(itrack)); + + // Set the track parameters + track->setTrackParameters(lc_track->getD0(), + lc_track->getPhi(), + lc_track->getOmega(), + lc_track->getTanLambda(), + lc_track->getZ0()); + + // Set the track type + track->setType(lc_track->getType()); + + // Set the track fit chi^2 + track->setChi2(lc_track->getChi2()); + + // Set the position of the extrapolated track at the ECal face. The + // extrapolation uses the full 3D field map. + const EVENT::TrackState* track_state + = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); + double position_at_ecal[3] = { + track_state->getReferencePoint()[1], + track_state->getReferencePoint()[2], + track_state->getReferencePoint()[0] + }; + track->setPositionAtEcal(position_at_ecal); + + // Get the collection of LCRelations between GBL kink data variables + // (GBLKinkData) and the corresponding track. + EVENT::LCCollection* gbl_kink_data = + static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to GBLKinkData object + UTIL::LCRelationNavigator* gbl_kink_data_nav + = new UTIL::LCRelationNavigator(gbl_kink_data); + + // Get the list of GBLKinkData associated with the LCIO Track + EVENT::LCObjectVec gbl_kink_data_list + = gbl_kink_data_nav->getRelatedFromObjects(lc_track); + + // The container of GBLKinkData objects should only contain a + // single object. If not, throw an exception + if (gbl_kink_data_list.size() != 1) { + throw std::runtime_error("[ SvtDataProcessor ]: The collection " + + std::string(Collections::TRACK_DATA_REL) + + " has the wrong data structure."); + } + + // Get the list GBLKinkData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* gbl_kink_datum + = static_cast(gbl_kink_data_list.at(0)); + + // Set the lambda and phi kink values + for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { + track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); + track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); + } + + delete gbl_kink_data_nav; + + // Get the collection of LCRelations between track data variables + // (TrackData) and the corresponding track. + EVENT::LCCollection* track_data = static_cast( + event->getLCCollection(Collections::TRACK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to TrackData objects + UTIL::LCRelationNavigator* track_data_nav + = new UTIL::LCRelationNavigator(track_data); + + // Get the list of TrackData associated with the LCIO Track + EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); + + // The container of TrackData objects should only contain a single + // object. If not, throw an exception. + if (track_data_list.size() == 1) { + + // Get the TrackData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); + + // Check that the TrackData data structure is correct. If it's + // not, throw a runtime exception. + if (track_datum->getNDouble() != 12 || track_datum->getNFloat() != 1 + || track_datum->getNInt() != 1) { + throw std::runtime_error("[ SvtDataProcessor ]: The collection " + + std::string(Collections::TRACK_DATA) + + " has the wrong structure."); + } + + // Set the SvtTrack isolation values + for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { + track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); + } + + // Set the SvtTrack time + track->setTrackTime(track_datum->getFloatVal(0)); + + // Set the volume (top/bottom) in which the SvtTrack resides + track->setTrackVolume(track_datum->getIntVal(0)); + } + + delete track_data_nav; + + // Get the collection of 3D hits associated with a LCIO Track + EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); + + // Iterate through the collection of 3D hits (TrackerHit objects) + // associated with a track, find the corresponding hits in the HPS + // event and add references to the track + for (auto hit : lc_tracker_hits) { + + // Add a reference to the hit + track->addHit(hit_map[hit]); + } + } + + event->addCollection("Tracks", tracks_); + +} + +void SvtDataProcessor::finalize() { +} + +DECLARE_PROCESSOR(SvtDataProcessor); From b49bd790f7c727271aa6dc234cce80c31a1eb8f4 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 09:06:50 -0800 Subject: [PATCH 032/314] Class which contains parameters passed to a Processor. --- processing/include/ParameterSet.h | 201 ++++++++++++++++++++++++++++++ processing/src/ParameterSet.cxx | 173 +++++++++++++++++++++++++ 2 files changed, 374 insertions(+) create mode 100644 processing/include/ParameterSet.h create mode 100644 processing/src/ParameterSet.cxx diff --git a/processing/include/ParameterSet.h b/processing/include/ParameterSet.h new file mode 100644 index 000000000..f2c666fe8 --- /dev/null +++ b/processing/include/ParameterSet.h @@ -0,0 +1,201 @@ +/** + * @file ParameterSet.h + * @brief Class which contains parameters passed to a Processor. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _PARAMETER_SET_H_ +#define _PARAMETER_SET_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include +#include + +class ParameterSet { + + public: + + /** + * Get an integer by name or throw an exception if not available, or not the right type. + * @param name Name of the integer. + */ + int getInteger(const std::string& name) const; + + /** + * Get an integer by name or use the given default if not available. + * If the wrong type, throw an exception. + * @param name Name of the integer. + * @param defaultValue Default value to use if the parameter was not provided. + */ + + int getInteger(const std::string& name, int defaultValue) const; + + /** + * Get a double by name or throw an exception if not available, or not the right type. + * @param name Name of the double parameter. + */ + double getDouble(const std::string& name) const; + + /** + * Get a double by name or use the given default if not available. + * If the wrong type, throw an exception. + * @param name Name of the double parameter. + * @param defaultValue Default value to ue if the parameter was not provided. + */ + double getDouble(const std::string& name, double defaultValue) const; + + /** + * Get a string by name or throw an exception if not available, or not the right type. + * @param name Name of the string parameter. + */ + const std::string& getString(const std::string& name) const; + + /** + * Get a string by name or use the given default if not available. + * If the wrong type, throw an exception. + * @param name Name of the string parameter. + * @param defaultValue Default value to ue if the parameter was not provided. + */ + const std::string& getString(const std::string& name, const std::string& defaultValue) const; + + /** + * Get a vector of integers by name or throw an exception if not available, or not the right type. + * @param name Name of the vector of integers. + */ + const std::vector& getVInteger(const std::string& name) const; + + /** + * Get a vector of integers by name or use the given default if not available. + * If the wrong type, throw an exception. + * @param name Name of the vector of integers. + * @param defaultValue Default value to ue if the parameter was not provided. + */ + const std::vector& getVInteger(const std::string& name, const std::vector& defaultValue) const; + + /** + * Get a vector of doubles by name or throw an exception if not available, or not the right type. + * @param name Name of the vector of doubles. + */ + const std::vector& getVDouble(const std::string& name) const; + + /** + * Get a vector of doubles by name or use the given default if not available. + * If the wrong type, throw an exception. + * @param name Name of the vector of doubles. + * @param defaultValue Default value to ue if the parameter was not provided. + */ + const std::vector& getVDouble(const std::string& name, const std::vector& defaultValue) const; + + /** + * Get a vector of strings by name or throw an exception if not available, or not the right type. + * @param name Name of the vector of strings. + */ + const std::vector& getVString(const std::string& name) const; + + /** + * Get a vector of strings by name or use the given default if not available. + * If the wrong type, throw an exception. + * @param name Name of the vector of strings. + * @param defaultValue Default value to ue if the parameter was not provided. + */ + const std::vector& getVString(const std::string& name, const std::vector& defaultValue) const; + + /** + * Add an integer to the ParameterSet. + * @param name Name of the integer parameter. + * @param value Value of the integer parameter. + */ + void insert(const std::string& name, int value); + + /** + * Add a double to the ParameterSet. + * @param name Name of the double parameter. + * @param value Value of the double parameter. + */ + void insert(const std::string& name, double value); + + /** + * Add a string to the ParameterSet. + * @param name Name of the string parameter. + * @param value Value of the string parameter. + */ + void insert(const std::string& name, const std::string& value); + + /** + * Add a vector of integers to the ParameterSet. + * @param name Name of the integer vector parameter. + * @param values Values of the integer vector parameter. + */ + void insert(const std::string& name, const std::vector& values); + + /** + * Add a vector of doubles to the ParameterSet. + * @param name Name of the double vector parameter. + * @param values Values of the double vector parameter. + */ + void insert(const std::string& name, const std::vector& values); + + /** + * Add a vector of strings to the ParameterSet. + * @param name Name of the string vector parameter. + * @param values Values of the string vector parameter. + */ + void insert(const std::string& name, const std::vector& values); + + /** + * @enum Specifies the type of a parameter in a ParameterSet. + */ + typedef enum { + et_NoType, + et_Bool, + et_Integer, + et_Double, + et_String, + et_VInteger, + et_VDouble, + et_VString, + et_ParameterSet + } ElementType; + + /** + * @struct Element + * @brief Backing data structure containing parameter values + * + * @todo Fully document me! + */ + struct Element { + + Element() : et_{et_NoType} {;} + + Element(bool inval) : et_{et_Bool}, boolval_{inval} {;} + + Element(int inval) : et_{et_Integer}, intval_{inval} {;} + + Element(double inval) : et_ {et_Double}, doubleval_{inval} {;} + + Element(const std::string& inval) : et_ { et_String }, strval_ { inval } {;} + + Element(const std::vector& inval); + + Element(const std::vector& inval); + + Element(const std::vector& inval); + + ElementType et_; + bool boolval_{false}; + int intval_{0}; + double doubleval_{0}; + std::string strval_; + std::vector ivecVal_; + std::vector dvecVal_; + std::vector svecVal_; + ParameterSet* subsetVal_ { 0 }; + }; + + std::map elements_; +}; + +#endif // _PARAMETER_SET_H_ diff --git a/processing/src/ParameterSet.cxx b/processing/src/ParameterSet.cxx new file mode 100644 index 000000000..5aaf7fcd8 --- /dev/null +++ b/processing/src/ParameterSet.cxx @@ -0,0 +1,173 @@ + +#include "ParameterSet.h" + +void ParameterSet::insert(const std::string& name, int value) { + elements_[name] = Element(value); +} + +int ParameterSet::getInteger(const std::string& name) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + throw std::runtime_error("[ Parameter Not Found ]: Integer parameter '" + name + "' not found"); + } + if (ptr->second.et_ != et_Integer) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not an integer"); + } + return ptr->second.intval_; +} + +int ParameterSet::getInteger(const std::string& name, int defaultValue) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + return defaultValue; + } + if (ptr->second.et_ != et_Integer) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not an integer"); + } + return ptr->second.intval_; +} + +void ParameterSet::insert(const std::string& name, double value) { + elements_[name] = Element(value); +} + +double ParameterSet::getDouble(const std::string& name) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + throw std::runtime_error("[ Parameter Not Found ]: Double parameter '" + name + "' not found"); + } + if (ptr->second.et_ != et_Double) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a double"); + } + return ptr->second.doubleval_; +} + +double ParameterSet::getDouble(const std::string& name, double defaultValue) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + return defaultValue; + } + if (ptr->second.et_ != et_Double) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a double"); + } + return ptr->second.doubleval_; +} + +void ParameterSet::insert(const std::string& name, const std::string& value) { + elements_[name] = Element(value); +} + +const std::string& ParameterSet::getString(const std::string& name) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + throw std::runtime_error("[ Parameter Not Found ]: String parameter '" + name + "' not found"); + } + if (ptr->second.et_ != et_String) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a string"); + } + return ptr->second.strval_; +} + +const std::string& ParameterSet::getString(const std::string& name, const std::string& defaultValue) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + return defaultValue; + } + if (ptr->second.et_ != et_String) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a string"); + } + return ptr->second.strval_; +} + +/* --------------- Vectors of integers ------------------------*/ +ParameterSet::Element::Element(const std::vector& inval) : + et_{ParameterSet::et_VInteger}, ivecVal_(inval) { + } + +void ParameterSet::insert(const std::string& name, const std::vector& values) { + elements_[name] = Element(values); +} + +const std::vector& ParameterSet::getVInteger(const std::string& name) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + throw std::runtime_error("[ Parameter Not Found ]: Parameter '" + name + "' not found"); + } + if (ptr->second.et_ != et_VInteger) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a vector of integers"); + } + return ptr->second.ivecVal_; +} + +const std::vector& ParameterSet::getVInteger(const std::string& name, const std::vector& defaultValue) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + return defaultValue; + } + if (ptr->second.et_ != et_VInteger) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a vector of integers"); + } + return ptr->second.ivecVal_; +} + +/* --------------- Vectors of doubles ------------------------*/ +ParameterSet::Element::Element(const std::vector& inval) : + et_ { ParameterSet::et_VDouble }, dvecVal_(inval) { + } + +void ParameterSet::insert(const std::string& name, const std::vector& values) { + elements_[name] = Element(values); +} + +const std::vector& ParameterSet::getVDouble(const std::string& name) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + throw std::runtime_error("[ Parameter Not Found ]: Parameter '" + name + "' not found"); + } + if (ptr->second.et_ != et_VDouble) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a vector of doubles"); + } + return ptr->second.dvecVal_; +} + +const std::vector& ParameterSet::getVDouble(const std::string& name, const std::vector& defaultValue) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + return defaultValue; + } + if (ptr->second.et_ != et_VDouble) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a vector of doubles"); + } + return ptr->second.dvecVal_; +} + +/* --------------- Vectors of strings ------------------------*/ +ParameterSet::Element::Element(const std::vector& inval) : + et_{ParameterSet::et_VString}, svecVal_(inval) { + } + +void ParameterSet::insert(const std::string& name, const std::vector& values) { + elements_[name] = Element(values); +} + +const std::vector& ParameterSet::getVString(const std::string& name) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + throw std::runtime_error("[ Parameter Not Found ]: Parameter '" + name + "' not found"); + } + if (ptr->second.et_ != et_VString) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a vector of strings"); + } + return ptr->second.svecVal_; +} + +const std::vector& ParameterSet::getVString(const std::string& name, const std::vector& defaultValue) const { + std::map::const_iterator ptr = elements_.find(name); + if (ptr == elements_.end()) { + return defaultValue; + } + if (ptr->second.et_ != et_VString) { + throw std::runtime_error("[ Parameter Type Error ]: Parameter '" + name + "' is not a vector of strings"); + } + return ptr->second.svecVal_; +} From a4e333debf21633a6500240cfbcabe9989a117f9 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 09:18:55 -0800 Subject: [PATCH 033/314] Allow setting of processor parameters. --- processing/include/ConfigurePython.h | 9 +++++---- processing/include/Processor.h | 14 +++++++++++--- processing/python/HpstrConf.py | 5 +++++ processing/src/ConfigurePython.cxx | 11 +++-------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/processing/include/ConfigurePython.h b/processing/include/ConfigurePython.h index fc4d2b9a3..56d0a2dff 100644 --- a/processing/include/ConfigurePython.h +++ b/processing/include/ConfigurePython.h @@ -21,11 +21,12 @@ #include #include -//------------// -// svt-qa // -//------------// +//-----------// +// hpstr // +//-----------// #include "Process.h" #include "ProcessorFactory.h" +#include "ParameterSet.h" class ConfigurePython { @@ -72,7 +73,7 @@ class ConfigurePython { struct ProcessorInfo { std::string classname_; std::string instancename_; - //ParameterSet params_; + ParameterSet params_; }; /** The sequence of EventProcessor objects to be executed in order. */ diff --git a/processing/include/Processor.h b/processing/include/Processor.h index baac2c427..570970da7 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -16,6 +16,7 @@ // hpstr // //-----------// #include "Event.h" +#include "ParameterSet.h" // Forward declarations class Process; @@ -51,10 +52,11 @@ class Processor { virtual ~Processor() {;} /** - * Process the event and put new data products into it. - * @param event The Event to process. + * Callback for the EventProcessor to configure itself from the given set of parameters. + * @param parameters ParameterSet for configuration. */ - virtual void process(Event* event) = 0; + virtual void configure(const ParameterSet& parameters) { + } /** * Callback for the Processor to take any necessary @@ -63,6 +65,12 @@ class Processor { */ virtual void initialize() = 0; + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual void process(Event* event) = 0; + /** * Callback for the Processor to take any necessary * action when the processing of events finishes, such as diff --git a/processing/python/HpstrConf.py b/processing/python/HpstrConf.py index 1a7d014ae..705d34980 100644 --- a/processing/python/HpstrConf.py +++ b/processing/python/HpstrConf.py @@ -4,9 +4,14 @@ class Processor: def __init__(self, instance_name, class_name): self.instance_name = instance_name self.class_name = class_name + self.parameters = {} def toString(self): print "\tProcessor( %s of instance %s )" % (self.instance_name, self.class_name) + if len(self.parameters) > 0: + print "\t\tParameters: " + for key, value in self.parameters.items(): + print "\t\t\t [ %s ]: %s" % (key, value) class Process: diff --git a/processing/src/ConfigurePython.cxx b/processing/src/ConfigurePython.cxx index f3f71b14b..24884e3eb 100644 --- a/processing/src/ConfigurePython.cxx +++ b/processing/src/ConfigurePython.cxx @@ -111,9 +111,7 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], pi.classname_ = stringMember(processor, "class_name"); pi.instancename_ = stringMember(processor, "instance_name"); std::cout << pi.classname_ << std::endl; - std::cout << "Hereeeeeee:" << std::endl; - /* PyObject* params = PyObject_GetAttrString(processor, "parameters"); if (params != 0 && PyDict_Check(params)) { PyObject *key(0), *value(0); @@ -121,10 +119,7 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], while (PyDict_Next(params, &pos, &key, &value)) { std::string skey = PyString_AsString(key); - if (PyBool_Check(value)) { - pi.params_.insert(skey, bool(PyInt_AsLong(value))); - //printf("Bool Key: %s\n",skey.c_str()); - } else if (PyInt_Check(value)) { + if (PyInt_Check(value)) { pi.params_.insert(skey, int(PyInt_AsLong(value))); //printf("Int Key: %s\n",skey.c_str()); } else if (PyFloat_Check(value)) { @@ -158,7 +153,7 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], } } } - }*/ + } sequence_.push_back(pi); } @@ -219,7 +214,7 @@ Process* ConfigurePython::makeProcess() { if (ep == 0) { throw std::runtime_error("[ ConfigurePython ]: Unable to create instance of " + proc.instancename_); } - //ep->configure(proc.params_); + ep->configure(proc.params_); p->addToSequence(ep); } From 577fedc815a77055649009b774fbcff7167e2960 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 14:53:33 -0800 Subject: [PATCH 034/314] Class to encapsulate information about a particle. --- event/include/Particle.h | 253 +++++++++++++++++++++++++++++++++++++++ event/src/Particle.cxx | 73 +++++++++++ 2 files changed, 326 insertions(+) create mode 100644 event/include/Particle.h create mode 100644 event/src/Particle.cxx diff --git a/event/include/Particle.h b/event/include/Particle.h new file mode 100644 index 000000000..63ab901c7 --- /dev/null +++ b/event/include/Particle.h @@ -0,0 +1,253 @@ +/** + * @file Particle.h + * @brief Class used to encapsulate information about a particle. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _PARTICLE_H_ +#define _PARTICLE_H_ + +//----------// +// ROOT // +//----------// +#include +#include +#include +#include + +//class EcalCluster; + +class Particle : public TObject { + + public: + + /** Default Constructor. */ + Particle(); + + /** Destructor. */ + ~Particle(); + + /** Reset this Particle object */ + void Clear(Option_t *option=""); + + /** + * Add a reference to a Track object. This will be used to + * associate a particle with the track that composes it. + * + * @param track Track whose reference will be added + */ + void addTrack(TObject* track); + + /** + * @return An array of references to the tracks associated with this + * particle + */ + TRefArray* getTracks() const; + + /** + * Add a reference to an CalorimeterCluster object. This will be used + * to associated a particle with the calorimeter cluster that composes it. + * + * @param ecal_cluster Ecal cluster whose reference will be added + */ + //void addCluster(EcalCluster* ecal_cluster); + + + /** + * @return An array of references to the calorimeter clusters associated + * with this particle + */ + //TRefArray* getClusters() const; + + /** + * Add a reference to an Particle object. This will be used to + * add daughter particles to this particle. + * + * @param particle Daughter particle composing this particle + */ + void addParticle(Particle* particle); + + /** + * Get the daughter particles composing this particle. + * + * @return An array of references to the daughter particles associated + * with this particle + */ + TRefArray* getParticles() const; + + /** + * Set the charge of the particle. + * + * @param charge_ Particle charge + */ + void setCharge(const int charge) { charge_ = charge; }; + + /** + * Set the overall goodness of the PID for this particle. + * + * @param goodness_pid_ The goodness of the PID. + */ + void setGoodnessOfPID(const double goodness_pid) { goodness_pid_ = goodness_pid; }; + + /** + * Set the type of this particle. + * + * @param type The type of this particle + */ + void setType(const int type) { type_ = type; }; + + /** + * Set the PDG ID of this particle. + * + * @param pdg The PDG ID of this particle + */ + void setPDG(const int pdg) { pdg_ = pdg; }; + + /** + * Set the energy of the particle in GeV. + * + * @param energy The energy of this particle + */ + void setEnergy(const double energy) { energy_ = energy; }; + + /** + * Set the invariant mass of the particle in GeV. + * + * @param mass The invariant mass of the particle + */ + void setMass(const double mass) { mass_ = mass; }; + + /** + * Set the momentum of the particle in GeV. + * + * @param momentum An array containing the three momentum components + * of the particle. + */ + void setMomentum(const double* momentum); + + /** + * Set the corrected momentum of the paritcle in GeV. + * + * @param momentum An array containing the three momentum components + * of the particle. + */ + void setCorrMomentum(const double* momentum); + + /** + * Set the vertex position of the particle. + * + * @param vtx_pos An array containing the three vertex position + * components of the particle + */ + void setVertexPosition(const float* vtx_pos); + + /** + * Set the chi^2 of the vertex fit. + * + * @param vtx_fit_chi2 The chi^2 of the vertex fit + */ + void setVertexFitChi2(const double vtx_fit_chi2) { vtx_fit_chi2_ = vtx_fit_chi2; }; + + /** @return The particle charge. */ + int getCharge() const { return charge_; }; + + /** @return The goodness of the PID. */ + double getGoodnessOfPID() const { return goodness_pid_; }; + + /** @return The type of this particle. */ + int getType() const { return type_; }; + + /** @return The particle ID. */ + int getPDG() const { return pdg_; }; + + /** @return The particle energy in GeV. */ + double getEnergy() const { return energy_; }; + + /** @return The invariant mass of the particle in GeV. */ + double getMass() const { return mass_; }; + + /** @return The momentum of the particle. */ + std::vector getMomentum() const; + + /** @return The corrected momentum of the paritcle in GeV. */ + std::vector getCorrMomentum() const; + + /** @return The vertex position of the particle. */ + std::vector getVertexPosition() const; + + /** @return The chi^2 of the vertex fit. */ + double getVertexFitChi2() const { return vtx_fit_chi2_; }; + + ClassDef(Particle, 1); + + private: + + /** An array of references to tracks associated with this particle */ + TRefArray* tracks_{new TRefArray{}}; + + /** + * An array of references to calorimeter clusters associated with this + * particle + */ + TRefArray* clusters_{new TRefArray{}}; + + /** + * An array of references to daughter particles associated with this + * particle + */ + TRefArray* particles_{new TRefArray{}}; + + /** The number of daughters associated with this particle */ + int n_daughters_{0}; + + /** The charge of this particle */ + int charge_{-9999}; + + /** The type of this particle */ + int type_{-9999}; + + /** The PDG ID of this particle */ + int pdg_{-9999}; + + /** The goodness of PID of this particle. */ + double goodness_pid_{-9999}; + + /** The x component of the momentum of this particle in GeV */ + double px_{-9999}; + + /** The x component of the corrected momentum of this particle in GeV */ + double px_corr_{-9999}; + + /** The y component of the momentum of this particle in GeV */ + double py_{-9999}; + + /** The y component of the corrected momentum of this particle in GeV */ + double py_corr_{-9999}; + + /** The z component of the momentum of this particle in GeV */ + double pz_{-9999}; + + /** The z component of the corrected momentum of this particle in GeV */ + double pz_corr_{-9999}; + + /** The x component of the vertex of this particle in mm*/ + double vtx_x_{-9999}; + + /** The y component of the vertex of this particle in mm */ + double vtx_y_{-9999}; + + /** The z component of the vertex of this particle in mm */ + double vtx_z_{-9999}; + + /** The chi^2 of the vertex fit */ + double vtx_fit_chi2_{-9999}; + + /** The energy of the particle in GeV */ + double energy_{-9999}; + + /** The invariant mass of the particle in GeV */ + double mass_{-9999}; + +}; // Particle + +#endif // _PARTICLE_H_ diff --git a/event/src/Particle.cxx b/event/src/Particle.cxx new file mode 100644 index 000000000..2419e9625 --- /dev/null +++ b/event/src/Particle.cxx @@ -0,0 +1,73 @@ +/** + * @file Particle.cxx + * @brief Class used to encapsulate information about a particle. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "Particle.h" + +ClassImp(Particle) + +Particle::Particle() + : TObject() { +} + +Particle::~Particle() { + Clear(); + delete tracks_; + delete clusters_; + delete particles_; +} + +void Particle::Clear(Option_t* /* option */) { + TObject::Clear(); + tracks_->Delete(); + clusters_->Delete(); + particles_->Delete(); + n_daughters_ = 0; +} + +void Particle::addTrack(TObject* track) { + tracks_->Add(track); +} + +/*void Particle::addCluster(CalorimeterCluster* cluster) { + clusters_->Add(static_cast(cluster)); +}*/ + +void Particle::addParticle(Particle* particle) { + ++n_daughters_; + particles_->Add(static_cast(particle)); +} + +void Particle::setMomentum(const double* momentum) { + px_ = momentum[0]; + py_ = momentum[1]; + pz_ = momentum[2]; +} + +std::vector Particle::getMomentum() const { return { px_, py_, pz_ }; } + +void Particle::setCorrMomentum(const double* momentum) { + px_corr_ = momentum[0]; + py_corr_ = momentum[1]; + pz_corr_ = momentum[2]; +} + +std::vector Particle::getCorrMomentum() const { return { px_, py_, pz_ }; }; + +void Particle::setVertexPosition(const float* vtx_pos) { + vtx_x_ = static_cast(vtx_pos[0]); + vtx_y_ = static_cast(vtx_pos[1]); + vtx_z_ = static_cast(vtx_pos[2]); +} + +std::vector Particle::getVertexPosition() const { + return { vtx_x_, vtx_y_, vtx_z_ }; +} + +TRefArray* Particle::getTracks() const { return tracks_; } + +//TRefArray* Particle::getClusters() const { return clusters_; } + +TRefArray* Particle::getParticles() const { return particles_; } From 2db1d4c4efb2a39b055fd9c327e4fae1deb21fa0 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 14:54:13 -0800 Subject: [PATCH 035/314] Add Final state particles to the list of collections. --- event/include/Collections.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/event/include/Collections.h b/event/include/Collections.h index 14af2f9e7..64bdd5c09 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -27,6 +27,9 @@ namespace Collections { /** Name of the collection containing Track to TrackData LCRelations */ constexpr const char* TRACK_DATA_REL{"TrackDataRelations"}; + /** Name of the collection containing Final State Particles. */ + constexpr const char* FINAL_STATE_PARTICLES{"FinalStateParticles"}; + } #endif // _COLLECTION_H_ From 80c78f16d01f63b7ac6d200b99ef1f491c8d7bb7 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 14:54:56 -0800 Subject: [PATCH 036/314] Add method to retrieve a collection from the event. --- event/include/Event.h | 28 ++++++++++++++++++++++++++-- event/src/Event.cxx | 20 ++++++++++++++++++-- processing/src/EventFile.cxx | 1 + 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/event/include/Event.h b/event/include/Event.h index d21969507..c3fd7fd19 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -8,6 +8,11 @@ #ifndef __EVENT_H__ #define __EVENT_H__ +//----------------// +// C++ StdLib // +//----------------// +#include + //----------// // LCIO // //----------// @@ -38,7 +43,13 @@ class Event { */ void addCollection(const std::string name, TClonesArray* collection); - + /** + * @param name Name of the collection + * + * @return Get a collection from the event. + */ + TClonesArray* getCollection(const std::string name); + /** * Clear all of the collections in the event */ @@ -55,6 +66,13 @@ class Event { return static_cast(lc_event_->getCollection(name)); }; + /** + * Set the current entry. + * + * @param The current entry. + */ + void setEntry(const int entry) { entry_ = entry; }; + private: /** The ROOT tree containing the event. */ @@ -64,7 +82,13 @@ class Event { EVENT::LCEvent* lc_event_{nullptr}; /** Container with all TClonesArray collections. */ - std::map collections_; + std::map collections_; + + /** Container will all branches. */ + std::map branches_; + + /** The current entry. */ + int entry_{0}; }; // Event diff --git a/event/src/Event.cxx b/event/src/Event.cxx index b4ef98647..bf6441c38 100644 --- a/event/src/Event.cxx +++ b/event/src/Event.cxx @@ -21,12 +21,28 @@ void Event::addCollection(const std::string name, TClonesArray* collection) { if (collections_.find(name) != collections_.end()) return; // Add a branch with the given name to the event tree. - tree_->Branch(name.c_str(), collection, 1000000, 3); + branches_[name] = tree_->Branch(name.c_str(), collection, 1000000, 3); - // Kepp track of which events were added to the event + // Keep track of which events were added to the event collections_[name] = collection; } +TClonesArray* Event::getCollection(const std::string name) { + + // Check if the collection already exist + auto itc = collections_.find(name); + auto itb = branches_.find(name); + + if (itc != collections_.end()) { + if (itb != branches_.end()) { + itb->second->GetEntry(entry_); + } + return itc->second; + } else { + throw std::runtime_error("Collection not found."); + } +} + void Event::Clear() { for (auto& collection : collections_) { diff --git a/processing/src/EventFile.cxx b/processing/src/EventFile.cxx index ed6549509..30d787730 100644 --- a/processing/src/EventFile.cxx +++ b/processing/src/EventFile.cxx @@ -29,6 +29,7 @@ bool EventFile::nextEvent() { if ((lc_event_ = lc_reader_->readNextEvent()) == 0) return false; event_->setLCEvent(lc_event_); + event_->setEntry(entry_); ++entry_; return true; From 061d8095fe2c3b1a8b41174fc7e9f417c0ea0861 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 14:55:23 -0800 Subject: [PATCH 037/314] Add Particle to the ROOT dictionary. --- event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 1 + 2 files changed, 2 insertions(+) diff --git a/event/include/EventDef.h b/event/include/EventDef.h index 3475894f7..e0cb0a32e 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -1,4 +1,5 @@ #include "Event.h" +#include "Particle.h" #include "Track.h" #include "TrackerHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index fdfa7f2ed..5455ba1c4 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -6,6 +6,7 @@ #pragma link C++ nestedclasses; +#pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class TrackerHit+; From 303e321614728de2bff270b61a93dbb806893fe3 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 14:56:03 -0800 Subject: [PATCH 038/314] Remove references to TrackerHit and Particle and instead use TObject. --- event/include/Track.h | 35 +++++++++++------------------------ event/src/Track.cxx | 4 ++-- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/event/include/Track.h b/event/include/Track.h index 04f432a66..291f43392 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -21,11 +21,6 @@ #include #include -//----------// -// hpstr // -//----------// -#include "TrackerHit.h" - class Track : public TObject { public: @@ -44,7 +39,10 @@ class Track : public TObject { * * @param hit : A TrackerHit object */ - void addHit(TrackerHit* hit); + void addHit(TObject* hit); + + /** @return A reference to the hits associated with this track. */ + TRefArray* getSvtHits() const { return tracker_hits_; }; /** * Set the track parameters. @@ -112,12 +110,15 @@ class Track : public TObject { void setTrackVolume(const int track_volume) { track_volume_ = track_volume; }; /** - * Set the HpsParticle associated with this track. This can be used to + * Set the Particle associated with this track. This can be used to * retrieve additional track properties such as the momentum and charge. * - * @param fs_particle : Final state HpsParticle associated with this track + * @param particle : Final state particle associated with this track */ - //void setParticle(HpsParticle* fs_particle) { this->fs_particle = (TObject*) fs_particle; }; + void setParticle(TObject* particle) { particle_ = particle; }; + + /** @return The {@link Particle} associated with this track. */ + TObject* getParticle() const { return static_cast(particle_.GetObject()); }; /** * Set the extrapolated track position at the Ecal face. The @@ -188,20 +189,6 @@ class Track : public TObject { */ double getPhiKink(const int layer) const { return phi_kinks_[layer]; } - /** - * Get an array of references to the hits associated with this track. - * - * @return A reference to the hits associated with this track. - */ - TRefArray* getSvtHits() const { return tracker_hits_; }; - - /** - * Get the {@link HpsParticle} associated with this track. - * - * @return The {@link HpsParticle} associated with this track. - */ - //HpsParticle* getParticle() const { return (HpsParticle*) this->fs_particle.GetObject(); }; - /** * @returns True if the track is in the top SVT volume, false otherwise. */ @@ -218,7 +205,7 @@ class Track : public TObject { TRefArray* tracker_hits_{new TRefArray{}}; /** Reference to the reconstructed particle associated with this track. */ - //TRef fs_particle; + TRef particle_; /** Array used to store the isolation variables for each of the sensor layers. */ double isolation_[12]; diff --git a/event/src/Track.cxx b/event/src/Track.cxx index 48a1ed26b..b24f3f23e 100644 --- a/event/src/Track.cxx +++ b/event/src/Track.cxx @@ -53,7 +53,7 @@ std::vector Track::getPositionAtEcal() { return { x_at_ecal_, y_at_ecal_ // return ((HpsParticle*) this->fs_particle.GetObject())->getMomentum(); //} -void Track::addHit(TrackerHit* hit) { +void Track::addHit(TObject* hit) { ++n_hits_; - tracker_hits_->Add(static_cast(hit)); + tracker_hits_->Add(hit); } From b90a4b626b52d98f505b96c29051dfa71244722b Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 10 Dec 2018 15:05:36 -0800 Subject: [PATCH 039/314] Processor used to translate LCIO ReconstructedParticles to DST files. --- processors/include/ParticleProcessor.h | 87 +++++++++++++ processors/src/ParticleProcessor.cxx | 170 +++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 processors/include/ParticleProcessor.h create mode 100644 processors/src/ParticleProcessor.cxx diff --git a/processors/include/ParticleProcessor.h b/processors/include/ParticleProcessor.h new file mode 100644 index 000000000..c9c23d565 --- /dev/null +++ b/processors/include/ParticleProcessor.h @@ -0,0 +1,87 @@ +/** + * @file ParticleProcessor.h + * @brief Processor used to translate LCIO ReconstructedParticles to DST + * Particle objects. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _PARTICLE_PROCESSOR_H_ +#define _PARTICLE_PROCESSOR_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +//#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Particle.h" +#include "Processor.h" +#include "Track.h" + +class ParticleProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + ParticleProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~ParticleProcessor(); + + /** + * Callback for the EventProcessor to configure itself from the given set of parameters. + * @param parameters ParameterSet for configuration. + */ + virtual void configure(const ParameterSet& parameters); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual void process(Event* event); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Map to hold all particle collections. */ + std::map collections_; + +}; // ParticleProcessor + +#endif // _PARTICLE_PROCESSOR_H_ diff --git a/processors/src/ParticleProcessor.cxx b/processors/src/ParticleProcessor.cxx new file mode 100644 index 000000000..86455aab4 --- /dev/null +++ b/processors/src/ParticleProcessor.cxx @@ -0,0 +1,170 @@ +/** + * @file ParticleProcessor.cxx + * @brief Processor used to translate LCIO ReconstructedParticles to DST + * Particle objects. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "ParticleProcessor.h" + +ParticleProcessor::ParticleProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +ParticleProcessor::~ParticleProcessor() { +} + +void ParticleProcessor::configure(const ParameterSet& parameters) { + + std::vector collection_names = parameters.getVString("Collections"); + for (auto const &collection_name : collection_names) { + std::cout << "[ ParticleProcessor ]: Processing Collection: " + << collection_name << std::endl; + + // Create a new TClonesArray collection + collections_[collection_name] = new TClonesArray("Particle", 1000000); + } + +} + +void ParticleProcessor::initialize() { +} + +void ParticleProcessor::process(Event* event) { + + for (auto& collections : collections_) { + + // Get the collection from the event + EVENT::LCCollection* lc_particles = event->getLCCollection(collections.first); + + // Loop through all of the particles in the event + for (int iparticle = 0; iparticle < lc_particles->getNumberOfElements(); ++iparticle) { + + // Get a particle from the LCEvent + EVENT::ReconstructedParticle* lc_particle + = static_cast(lc_particles->getElementAt(iparticle)); + + // Add a particle to the event + Particle* particle = static_cast(collections.second->ConstructedAt(iparticle)); + + // Set the charge of the HpsParticle + particle->setCharge(lc_particle->getCharge()); + + // Set the HpsParticle type + particle->setType(lc_particle->getType()); + + // Set the energy of the HpsParticle + particle->setEnergy(lc_particle->getEnergy()); + + // Set the momentum of the HpsParticle + particle->setMomentum(lc_particle->getMomentum()); + + // Set the mass of the HpsParticle + particle->setMass(lc_particle->getMass()); + + // Set the goodness of PID for the HpsParticle + particle->setGoodnessOfPID(lc_particle->getGoodnessOfPID()); + + // Loop through all of the tracks associated with the particle + // and add references to the Particle object. + for (auto const &lc_track : lc_particle->getTracks()) { + + TClonesArray* tracks = event->getCollection("Tracks"); + + // Loop through all of the tracks in the HpsEvent and find the one + // that matches the track associated with the particle + for (int itrack = 0; itrack < tracks->GetEntriesFast(); ++itrack) { + Track* track = static_cast(tracks->At(itrack)); + + // Use the track chi^2 to find the match + // TODO: Verify that the chi^2 is unique enough to find the match + if (lc_track->getChi2() == track->getChi2()) { + + // Add a reference to the track + particle->addTrack(track); + + // If the particle is a final state particle, add a + // reference from the corresponding track to the particle + if (collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) { + track->setParticle(particle); + } + break; + } + } + + } + + /*for (auto const &cluster : lc_particle->getClusters()) { + + // Loop through all of the clusters in the HpsEvent and find the one + // that matches the cluster associated with the particle + for (int cluster_n = 0; cluster_n < hps_event->getNumberOfEcalClusters(); ++cluster_n) { + + // Use the cluster energy to find the match + // TODO: Verify that the cluster enegy is unique enough to find a match + if (cluster->getEnergy() == hps_event->getEcalCluster(cluster_n)->getEnergy()) { + particle->addCluster(hps_event->getEcalCluster(cluster_n)); + break; + } + } + }*/ + + // Only add vertex information if the particle is not a final state particle + if (collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) { + // Set the PDG ID of the particle + particle->setPDG(lc_particle->getParticleIDUsed()->getPDG()); + continue; + } + + // Set the vertex position of the particle + EVENT::Vertex* vtx = static_cast(lc_particle->getStartVertex()); + particle->setVertexPosition(vtx->getPosition()); + + // Set the vertex chi2 + particle->setVertexFitChi2(vtx->getChi2()); + + // + // If the particle has daughter particles, add the daughters to the Particle + // + + // Loop through all of the daughter particles associated with the particle + /*for (auto const &daughter : lc_particle->getParticles()) { + + // Loop through all of the final state particles in the HpsEvent and + // find the one that matches the daughters associated with the particles + for (int d_particle_n = 0; d_particle_n < hps_event->getNumberOfParticles(HpsParticle::FINAL_STATE_PARTICLE); ++d_particle_n) { + + HpsParticle* daughter_particle + = hps_event->getParticle(HpsParticle::FINAL_STATE_PARTICLE, d_particle_n); + + // Try to find the match between a final state HpsParticle + // and ReconstructedParticle daughter. For now, use the + // momentum as the matching criterion. + // TODO: Verify that the track momentum is always unique in an event. + if (daughter->getMomentum()[0] == daughter_particle->getMomentum()[0] + && daughter->getMomentum()[1] == daughter_particle->getMomentum()[1] + && daughter->getMomentum()[2] == daughter_particle->getMomentum()[2]) { + + particle->addParticle(daughter_particle); + + if (daughter_particle->getTracks()->GetEntriesFast() != 0) + particle->addTrack((SvtTrack*) daughter_particle->getTracks()->At(0)); + + if (daughter_particle->getClusters()->GetEntriesFast() != 0) + particle->addCluster((EcalCluster*) daughter_particle->getClusters()->At(0)); + + break; + } + } + }*/ + } + + // Add the hit collection to the event + event->addCollection(collections.first, collections.second); + } +} + +void ParticleProcessor::finalize() { +} + +DECLARE_PROCESSOR(ParticleProcessor); From 52f50776f0d4830669f658fb4d731070ecc0df03 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Tue, 11 Dec 2018 15:20:25 -0800 Subject: [PATCH 040/314] Class used to encapsulate calorimeter cluster information. --- event/include/CalorimeterCluster.h | 119 +++++++++++++++++++++++++++++ event/src/CalorimeterCluster.cxx | 36 +++++++++ 2 files changed, 155 insertions(+) create mode 100644 event/include/CalorimeterCluster.h create mode 100644 event/src/CalorimeterCluster.cxx diff --git a/event/include/CalorimeterCluster.h b/event/include/CalorimeterCluster.h new file mode 100644 index 000000000..42ae45212 --- /dev/null +++ b/event/include/CalorimeterCluster.h @@ -0,0 +1,119 @@ +/** + * @file CalorimeterCluster.cxx + * @brief Class used to encapsulate calorimeter cluster information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _CALORIMETER_CLUSTER_H__ +#define _CALORIMETER_CLUSTER_H__ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include +#include +#include +#include + +class CalorimeterCluster : public TObject { + + public: + + /** Constructor */ + CalorimeterCluster(); + + /** Destructor */ + ~CalorimeterCluster(); + + /** Reset the Cluster object */ + void Clear(Option_t *option=""); + + /** + * Add a reference to a calorimeter hit composing this cluster. + * + * @param hit : Calorimeter hit composing with this cluster + */ + void addHit(TObject* hit); + + /** + * @return An array of references to the calorimeter hits composing + * this cluster. + */ + TRefArray* getHits() const { return hits_; } + + /** + * Set the position of the calorimeter cluster. + * + * @param position : The position of the calorimeter cluster + */ + void setPosition(const float* position); + + /** @return The position of the calorimeter cluster. */ + std::vector getPosition() const { return { x_, y_, z_ }; }; + + /** + * Set the energy of the calorimeter cluster. + * + * @param energy : The energy of the calorimeter cluster. + */ + void setEnergy(const double energy) { energy_ = energy; }; + + /** @return The energy of the calorimeter cluster. */ + double getEnergy() const { return energy_; }; + + /** + * Set the time of the calorimeter clusters. + * + * @param time The cluster time + */ + void setTime(const double time) { time_ = time; }; + + /** @return The time of the cluster. */ + double getTime() const { return time_; }; + + /** + * Set the cluster seed i.e. the hit with the highest energy. + * + * @param seed The cluster seed. + */ + void setSeed(TObject* seed_hit) { seed_hit_ = seed_hit; }; + + /** @return The seed hit of the cluster. */ + TObject* getSeed() const { return static_cast(seed_hit_.GetObject()); }; + + ClassDef(CalorimeterCluster, 1); + + private: + + /** An array of references to the hits associated withi this cluster. */ + TRefArray* hits_{new TRefArray{}}; + + /** A reference to the seed hit of this cluster. */ + TRef seed_hit_; + + /** The number of hits composing this cluster. */ + int n_hits_{0}; + + /** The x position of the cluster in (mm). */ + double x_{-9999}; + + /** The y position of the cluster in (mm). */ + double y_{-9999}; + + /** The z position of the cluster in (mm). */ + double z_{-9999}; + + /** The energy of the cluster in GeV. */ + double energy_{-9999}; + + /** The cluster time. */ + double time_{-9999}; + +}; // CalorimeterCluster + +#endif // _CALORIMETER_CLUSTER_H_ diff --git a/event/src/CalorimeterCluster.cxx b/event/src/CalorimeterCluster.cxx new file mode 100644 index 000000000..337022d52 --- /dev/null +++ b/event/src/CalorimeterCluster.cxx @@ -0,0 +1,36 @@ +/** + * @file CalorimeterCluster.cxx + * @brief Class used to encapsulate calorimeter cluster information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "CalorimeterCluster.h" + +ClassImp(CalorimeterCluster) + +CalorimeterCluster::CalorimeterCluster() + : TObject() { +} + +CalorimeterCluster::~CalorimeterCluster() { + Clear(); + delete hits_; +} + +void CalorimeterCluster::Clear(Option_t* /*option*/) { + TObject::Clear(); + hits_->Delete(); + seed_hit_ = nullptr; + n_hits_ = 0; +} + +void CalorimeterCluster::setPosition(const float* position) { + x_ = position[0]; + y_ = position[1]; + z_ = position[2]; +} + +void CalorimeterCluster::addHit(TObject* hit) { + ++n_hits_; + hits_->Add(hit); +} From 7e77f30d56a9a0ed86b543da67ac48f0655ec2f2 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Tue, 11 Dec 2018 15:21:37 -0800 Subject: [PATCH 041/314] Class that encapsulates calorimeter hit information. --- event/include/CalorimeterHit.h | 82 ++++++++++++++++++++++++++++++++++ event/src/CalorimeterHit.cxx | 26 +++++++++++ 2 files changed, 108 insertions(+) create mode 100644 event/include/CalorimeterHit.h create mode 100644 event/src/CalorimeterHit.cxx diff --git a/event/include/CalorimeterHit.h b/event/include/CalorimeterHit.h new file mode 100644 index 000000000..a3208a3bf --- /dev/null +++ b/event/include/CalorimeterHit.h @@ -0,0 +1,82 @@ +/** + * @file CalorimeterHit.h + * @brief Class that encapsulate calorimeter hit information + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __CALORIMETER_HIT_H__ +#define __CALORIMETER_HIT_H__ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include + +class CalorimeterHit : public TObject { + + public: + + /** Constructor */ + CalorimeterHit(); + + /** Destructor */ + ~CalorimeterHit(); + + /** Reset the hit object */ + void Clear(Option_t* option=""); + + /** + * Set the energy of the hit in GeV. + * + * @param energy The energy of the hit in GeV. + */ + void setEnergy(const double energy){ energy_ = energy; }; + + /** @return The energy of the hit in GeV. */ + double getEnergy() const { return energy_; }; + + /** + * Set the time of the hit in ns. + * + * @param time The time of the hit in ns. + */ + void setTime(const double time) { time_ = time; }; + + /** @return The time of the hit in ns. */ + double getTime() const { return time_; }; + + /** + * Set the indices of the crystal. + * + * @param index_x The index along x + * @param index_y The index along y + */ + void setCrystalIndices(int index_x_, int index_y_); + + /** @return The crystal indices. */ + std::vector getCrystalIndices() const { return { index_x_, index_y_ }; } + + ClassDef(CalorimeterHit, 1); + + private: + + /** The crystal index along x. */ + int index_x_{-9999}; + + /** The crystal index along y. */ + int index_y_{-9999}; + + /** The energy of the hit in GeV. */ + double energy_{-9999}; + + /** The time of the hit in ns. */ + double time_{0}; + +}; // CalorimeterHit + +#endif // _CALORIMETER_HIT_H_ diff --git a/event/src/CalorimeterHit.cxx b/event/src/CalorimeterHit.cxx new file mode 100644 index 000000000..6c9f73776 --- /dev/null +++ b/event/src/CalorimeterHit.cxx @@ -0,0 +1,26 @@ +/** + * @file CalorimeterHit.h + * @brief Class that encapsulate calorimeter hit information + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "CalorimeterHit.h" + +ClassImp(CalorimeterHit) + +CalorimeterHit::CalorimeterHit() + : TObject() { +} + +CalorimeterHit::~CalorimeterHit() { + Clear(); +} + +void CalorimeterHit::Clear(Option_t* /* options */) { + TObject::Clear(); +} + +void CalorimeterHit::setCrystalIndices(int index_x, int index_y) { + index_x = index_x; + index_y = index_y; +} From 7b0fa2dd48958e7f1438d12338e3272d070931ec Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Tue, 11 Dec 2018 15:22:01 -0800 Subject: [PATCH 042/314] Add CalorimeterHit/Cluster to the ROOT dictionary. --- event/include/EventDef.h | 2 ++ event/include/EventLinkDef.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/event/include/EventDef.h b/event/include/EventDef.h index e0cb0a32e..4257a2c90 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -1,4 +1,6 @@ +#include "CalorimeterCluster.h" +#include "CalorimeterHit.h" #include "Event.h" #include "Particle.h" #include "Track.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 5455ba1c4..137e8a98c 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -6,6 +6,8 @@ #pragma link C++ nestedclasses; +#pragma link C++ class CalorimeterCluster; +#pragma link C++ class CalorimeterHit; #pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class TrackerHit+; From f3c6f8a812c829e76a38191e610826efc939ba8f Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Tue, 11 Dec 2018 15:22:28 -0800 Subject: [PATCH 043/314] Small update to documentation. --- processing/include/Processor.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/processing/include/Processor.h b/processing/include/Processor.h index 570970da7..e37bb3ddf 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -52,7 +52,7 @@ class Processor { virtual ~Processor() {;} /** - * Callback for the EventProcessor to configure itself from the given set of parameters. + * Callback for the Processor to configure itself from the given set of parameters. * @param parameters ParameterSet for configuration. */ virtual void configure(const ParameterSet& parameters) { @@ -78,13 +78,6 @@ class Processor { */ virtual void finalize() = 0; - /** - * Callback for the Processor to configure itself from the given set of parameters. - * @param parameters ParameterSet for configuration. - */ - //virtual void configure(const ParameterSet& parameters) { - //} - /** * Internal function which is part of the ProcessorFactory machinery. * @param classname The class name of the processor. From 7a40f247ac835f1b6e83ec3cf87162c3b223e606 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 12 Dec 2018 15:32:22 -0800 Subject: [PATCH 044/314] Class used to encapsulate calorimeter cluster information. --- event/include/CalCluster.h | 119 +++++++++++++++++++++++++++++++++++++ event/src/CalCluster.cxx | 36 +++++++++++ 2 files changed, 155 insertions(+) create mode 100644 event/include/CalCluster.h create mode 100644 event/src/CalCluster.cxx diff --git a/event/include/CalCluster.h b/event/include/CalCluster.h new file mode 100644 index 000000000..8d053b204 --- /dev/null +++ b/event/include/CalCluster.h @@ -0,0 +1,119 @@ +/** + * @file CalCluster.cxx + * @brief Class used to encapsulate calorimeter cluster information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _CAL_CLUSTER_H__ +#define _CAL_CLUSTER_H__ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include +#include +#include +#include + +class CalCluster : public TObject { + + public: + + /** Constructor */ + CalCluster(); + + /** Destructor */ + ~CalCluster(); + + /** Reset the Cluster object */ + void Clear(Option_t *option=""); + + /** + * Add a reference to a calorimeter hit composing this cluster. + * + * @param hit : Cal hit composing with this cluster + */ + void addHit(TObject* hit); + + /** + * @return An array of references to the calorimeter hits composing + * this cluster. + */ + TRefArray* getHits() const { return hits_; } + + /** + * Set the position of the calorimeter cluster. + * + * @param position : The position of the calorimeter cluster + */ + void setPosition(const float* position); + + /** @return The position of the calorimeter cluster. */ + std::vector getPosition() const { return { x_, y_, z_ }; }; + + /** + * Set the energy of the calorimeter cluster. + * + * @param energy : The energy of the calorimeter cluster. + */ + void setEnergy(const double energy) { energy_ = energy; }; + + /** @return The energy of the calorimeter cluster. */ + double getEnergy() const { return energy_; }; + + /** + * Set the time of the calorimeter clusters. + * + * @param time The cluster time + */ + void setTime(const double time) { time_ = time; }; + + /** @return The time of the cluster. */ + double getTime() const { return time_; }; + + /** + * Set the cluster seed i.e. the hit with the highest energy. + * + * @param seed The cluster seed. + */ + void setSeed(TObject* seed_hit) { seed_hit_ = seed_hit; }; + + /** @return The seed hit of the cluster. */ + TObject* getSeed() const { return static_cast(seed_hit_.GetObject()); }; + + ClassDef(CalCluster, 1); + + private: + + /** An array of references to the hits associated withi this cluster. */ + TRefArray* hits_{new TRefArray{}}; + + /** A reference to the seed hit of this cluster. */ + TRef seed_hit_; + + /** The number of hits composing this cluster. */ + int n_hits_{0}; + + /** The x position of the cluster in (mm). */ + double x_{-9999}; + + /** The y position of the cluster in (mm). */ + double y_{-9999}; + + /** The z position of the cluster in (mm). */ + double z_{-9999}; + + /** The energy of the cluster in GeV. */ + double energy_{-9999}; + + /** The cluster time. */ + double time_{-9999}; + +}; // CalCluster + +#endif // _CALORIMETER_CLUSTER_H_ diff --git a/event/src/CalCluster.cxx b/event/src/CalCluster.cxx new file mode 100644 index 000000000..2059f4fa9 --- /dev/null +++ b/event/src/CalCluster.cxx @@ -0,0 +1,36 @@ +/** + * @file CalCluster.cxx + * @brief Class used to encapsulate calorimeter cluster information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "CalCluster.h" + +ClassImp(CalCluster) + +CalCluster::CalCluster() + : TObject() { +} + +CalCluster::~CalCluster() { + Clear(); + delete hits_; +} + +void CalCluster::Clear(Option_t* /*option*/) { + TObject::Clear(); + hits_->Delete(); + seed_hit_ = nullptr; + n_hits_ = 0; +} + +void CalCluster::setPosition(const float* position) { + x_ = position[0]; + y_ = position[1]; + z_ = position[2]; +} + +void CalCluster::addHit(TObject* hit) { + ++n_hits_; + hits_->Add(hit); +} From d5368d36ed75a898c40cb7436cbb9a26803bb6e5 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 12 Dec 2018 15:32:47 -0800 Subject: [PATCH 045/314] Class used to encapsulate calorimeter hit information. --- event/include/CalHit.h | 76 ++++++++++++++++++++++++++++++++++++++++++ event/src/CalHit.cxx | 26 +++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 event/include/CalHit.h create mode 100644 event/src/CalHit.cxx diff --git a/event/include/CalHit.h b/event/include/CalHit.h new file mode 100644 index 000000000..873b09682 --- /dev/null +++ b/event/include/CalHit.h @@ -0,0 +1,76 @@ +/** + * @file CalHit.h + * @brief Class that encapsulate calorimeter hit information + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _CALORIMETER_HIT_H_ +#define _CALORIMETER_HIT_H_ + +//----------// +// ROOT // +//----------// +#include + +class CalHit : public TObject { + + public: + + /** Constructor */ + CalHit(); + + /** Destructor */ + ~CalHit(); + + /** Reset the hit object */ + void Clear(Option_t* option=""); + + /** + * Set the energy of the hit in GeV. + * + * @param energy The energy of the hit in GeV. + */ + void setEnergy(const double energy){ energy_ = energy; }; + + /** @return The energy of the hit in GeV. */ + double getEnergy() const { return energy_; }; + + /** + * Set the time of the hit in ns. + * + * @param time The time of the hit in ns. + */ + void setTime(const double time) { time_ = time; }; + + /** @return The time of the hit in ns. */ + double getTime() const { return time_; }; + + /** + * Set the indices of the crystal. + * + * @param index_x The index along x + * @param index_y The index along y + */ + void setCrystalIndices(int index_x_, int index_y_); + + /** @return The crystal indices. */ + std::vector getCrystalIndices() const { return { index_x_, index_y_ }; } + + private: + + /** The crystal index along x. */ + int index_x_{-9999}; + + /** The crystal index along y. */ + int index_y_{-9999}; + + /** The energy of the hit in GeV. */ + double energy_{-9999}; + + /** The time of the hit in ns. */ + double time_{0}; + + ClassDef(CalHit, 1); +}; + +#endif diff --git a/event/src/CalHit.cxx b/event/src/CalHit.cxx new file mode 100644 index 000000000..33dced314 --- /dev/null +++ b/event/src/CalHit.cxx @@ -0,0 +1,26 @@ +/** + * @file CalHit.cxx + * @brief Class that encapsulate calorimeter hit information + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "CalHit.h" + +ClassImp(CalHit) + +CalHit::CalHit() + : TObject() { +} + +CalHit::~CalHit() { + Clear(); +} + +void CalHit::Clear(Option_t* /* options */) { + TObject::Clear(); +} + +void CalHit::setCrystalIndices(int index_x, int index_y) { + index_x_ = index_x; + index_y_ = index_y; +} From a34819ae74986284ac967bfadc80c28ed92d10ed Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 12 Dec 2018 15:33:55 -0800 Subject: [PATCH 046/314] Processor used to convert ECal LCIO data to ROOT. --- processors/include/ECalDataProcessor.h | 95 ++++++++++++++++ processors/src/ECalDataProcessor.cxx | 152 +++++++++++++++++++++++++ 2 files changed, 247 insertions(+) create mode 100644 processors/include/ECalDataProcessor.h create mode 100644 processors/src/ECalDataProcessor.cxx diff --git a/processors/include/ECalDataProcessor.h b/processors/include/ECalDataProcessor.h new file mode 100644 index 000000000..f5ecc828d --- /dev/null +++ b/processors/include/ECalDataProcessor.h @@ -0,0 +1,95 @@ +/** + * @file ECalDataProcessor.h + * @brief Processor used to convert ECal LCIO data to ROOT. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __ECAL_DATA_PROCESSOR_H__ +#define __ECAL_DATA_PROCESSOR_H__ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include + +//-----------// +// hpstr // +//-----------// +#include "CalCluster.h" +#include "CalHit.h" +#include "Collections.h" +#include "Processor.h" + +typedef long long long64; + +class ECalDataProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + ECalDataProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~ECalDataProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual void process(Event* event); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** + * Method to unpack field value from a calorimeter hit ID. + * + * @param field The field ID to unpack + * @param hit The CalorimeterHit whose ID will be used to unpack the + * the field value. + */ + UTIL::BitFieldValue getIdentifierFieldValue(std::string field, EVENT::CalorimeterHit* hit); + + /** TClonesArray collection containing all ECal hits. */ + TClonesArray* cal_hits_{nullptr}; + + /** TClonesArray collection containing all ECal clusters. */ + TClonesArray* clusters_{nullptr}; + + /** Encoding string describing cell ID. */ + const std::string encoder_string_{"system:6,layer:2,ix:-8,iy:-6"}; + +}; // ECalDataProcessor + +#endif // __ECAL_DATA_PROCESSOR_H__ diff --git a/processors/src/ECalDataProcessor.cxx b/processors/src/ECalDataProcessor.cxx new file mode 100644 index 000000000..7dfb7266d --- /dev/null +++ b/processors/src/ECalDataProcessor.cxx @@ -0,0 +1,152 @@ +/** + * @file ECalDataProcessor.cxx + * @brief Processor used to convert ECal LCIO data to ROOT. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "ECalDataProcessor.h" + +ECalDataProcessor::ECalDataProcessor(const std::string& name, Process& process) + : Processor(name, process) { + } + +ECalDataProcessor::~ECalDataProcessor() { +} + +void ECalDataProcessor::initialize() { + + cal_hits_ = new TClonesArray("CalHit", 100000); + clusters_ = new TClonesArray("CalCluster", 1000000); +} + +void ECalDataProcessor::process(Event* event) { + + // Attempt to retrieve the collection "TimeCorrEcalHits" from the event. If + // the collection doesn't exist, handle the DataNotAvailableCollection and + // attempt to retrieve the collection "EcalCalHits". If that collection + // doesn't exist, the DST maker will fail. + EVENT::LCCollection* hits{nullptr}; + std::string hits_coll_name = Collections::ECAL_TIME_CORR_HITS; + try { + hits = static_cast(event->getLCCollection(hits_coll_name)); + } catch (EVENT::DataNotAvailableException e) { + hits_coll_name = Collections::ECAL_HITS; + hits = static_cast(event->getLCCollection(hits_coll_name)); + } + + // A calorimeter hit + IMPL::CalorimeterHitImpl* lc_hit{nullptr}; + + // Get the collection of Ecal hits from the event. + std::map< std::pair, CalHit*> hit_map; + + // Loop through all of the hits and add them to event. + for (int ihit=0; ihit < hits->getNumberOfElements(); ++ihit) { + + // Get the ith hit from the LC Event. + IMPL::CalorimeterHitImpl* lc_hit + = static_cast(hits->getElementAt(ihit)); + + // Get the unique cell id of this hit. Combine it with the integer time, + // since a crystal can be hit more than once. + int id0 = lc_hit->getCellID0(); + + // 0.1 ns resolution is sufficient to distinguish any 2 hits on the same crystal. + int id1 = static_cast(10.0*lc_hit->getTime()); + + CalHit* cal_hit = static_cast(cal_hits_->ConstructedAt(ihit)); + + // Store the hit in the map for easy access later. + hit_map[ std::make_pair(id0,id1) ] = cal_hit; + + // Set the energy of the Ecal hit + cal_hit->setEnergy(lc_hit->getEnergy()); + + // Set the hit time of the Ecal hit + cal_hit->setTime(lc_hit->getTime()); + + // Set the indices of the crystal + int index_x = this->getIdentifierFieldValue("ix", lc_hit); + int index_y = this->getIdentifierFieldValue("iy", lc_hit); + + cal_hit->setCrystalIndices(index_x, index_y); + + } + + event->addCollection(hits_coll_name, cal_hits_); + + // Get the collection of Ecal clusters from the event + EVENT::LCCollection* clusters + = static_cast(event->getLCCollection(Collections::ECAL_CLUSTERS)); + + // Loop over all clusters and fill the event + for(int icluster = 0; icluster < clusters->getNumberOfElements(); ++icluster) { + + // Get an Ecal cluster from the LCIO collection + IMPL::ClusterImpl* lc_cluster = static_cast(clusters->getElementAt(icluster)); + + // Add a cluster to the event + CalCluster* cluster = static_cast(clusters_->ConstructedAt(icluster)); + + // Set the cluster position + cluster->setPosition(lc_cluster->getPosition()); + + // Set the cluster energy + cluster->setEnergy(lc_cluster->getEnergy()); + + // Get the ecal hits used to create the cluster + EVENT::CalorimeterHitVec lc_hits = lc_cluster->getCalorimeterHits(); + + // Loop over all of the Ecal hits and add them to the Ecal cluster. The + // seed hit is set to be the hit with the highest energy. The cluster time + // is set to be the hit time of the seed hit. + double senergy = 0; + double stime = 0; + CalHit* seed_hit{nullptr}; + for(int ihit = 0; ihit < (int) lc_hits.size(); ++ihit) { + + // Get an Ecal hit + lc_hit = static_cast(lc_hits[ihit]); + + int id0=lc_hit->getCellID0(); + int id1=(int)(10.0*lc_hit->getTime()); + + if (hit_map.find(std::make_pair(id0,id1)) == hit_map.end()) { + throw std::runtime_error("[ EcalDataProcessor ]: Hit not found in map, but is in the cluster."); + } else { + // Get the hit and add it to the cluster + CalHit* cal_hit = hit_map[std::make_pair(id0,id1)]; + cluster->addHit(cal_hit); + + if (senergy < lc_hit->getEnergy()) { + senergy = lc_hit->getEnergy(); + seed_hit = cal_hit; + stime = cal_hit->getTime(); + } + } + } + + // Set the time of the cluster + cluster->setTime(stime); + + // Set the cluster seed. + cluster->setSeed(seed_hit); + } + + event->addCollection(Collections::ECAL_CLUSTERS, clusters_); + +} + +void ECalDataProcessor::finalize() { +} + +UTIL::BitFieldValue ECalDataProcessor::getIdentifierFieldValue(std::string field, EVENT::CalorimeterHit* hit){ + + UTIL::BitField64 decoder(encoder_string_); + long64 value = long64( hit->getCellID0() & 0xffffffff ) | ( long64( hit->getCellID1() ) << 32 ) ; + decoder.setValue(value); + + return decoder[field]; +} + +DECLARE_PROCESSOR(ECalDataProcessor); From c62f93d5d17f901440ccc1eae31df2f7286e409b Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 12 Dec 2018 15:34:28 -0800 Subject: [PATCH 047/314] Renamed these classes. --- event/include/CalorimeterCluster.h | 119 ----------------------------- event/include/CalorimeterHit.h | 82 -------------------- event/src/CalorimeterCluster.cxx | 36 --------- event/src/CalorimeterHit.cxx | 26 ------- 4 files changed, 263 deletions(-) delete mode 100644 event/include/CalorimeterCluster.h delete mode 100644 event/include/CalorimeterHit.h delete mode 100644 event/src/CalorimeterCluster.cxx delete mode 100644 event/src/CalorimeterHit.cxx diff --git a/event/include/CalorimeterCluster.h b/event/include/CalorimeterCluster.h deleted file mode 100644 index 42ae45212..000000000 --- a/event/include/CalorimeterCluster.h +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @file CalorimeterCluster.cxx - * @brief Class used to encapsulate calorimeter cluster information. - * @author Omar Moreno, SLAC National Accelerator Laboratory - */ - -#ifndef _CALORIMETER_CLUSTER_H__ -#define _CALORIMETER_CLUSTER_H__ - -//----------------// -// C++ StdLib // -//----------------// -#include - -//----------// -// ROOT // -//----------// -#include -#include -#include -#include - -class CalorimeterCluster : public TObject { - - public: - - /** Constructor */ - CalorimeterCluster(); - - /** Destructor */ - ~CalorimeterCluster(); - - /** Reset the Cluster object */ - void Clear(Option_t *option=""); - - /** - * Add a reference to a calorimeter hit composing this cluster. - * - * @param hit : Calorimeter hit composing with this cluster - */ - void addHit(TObject* hit); - - /** - * @return An array of references to the calorimeter hits composing - * this cluster. - */ - TRefArray* getHits() const { return hits_; } - - /** - * Set the position of the calorimeter cluster. - * - * @param position : The position of the calorimeter cluster - */ - void setPosition(const float* position); - - /** @return The position of the calorimeter cluster. */ - std::vector getPosition() const { return { x_, y_, z_ }; }; - - /** - * Set the energy of the calorimeter cluster. - * - * @param energy : The energy of the calorimeter cluster. - */ - void setEnergy(const double energy) { energy_ = energy; }; - - /** @return The energy of the calorimeter cluster. */ - double getEnergy() const { return energy_; }; - - /** - * Set the time of the calorimeter clusters. - * - * @param time The cluster time - */ - void setTime(const double time) { time_ = time; }; - - /** @return The time of the cluster. */ - double getTime() const { return time_; }; - - /** - * Set the cluster seed i.e. the hit with the highest energy. - * - * @param seed The cluster seed. - */ - void setSeed(TObject* seed_hit) { seed_hit_ = seed_hit; }; - - /** @return The seed hit of the cluster. */ - TObject* getSeed() const { return static_cast(seed_hit_.GetObject()); }; - - ClassDef(CalorimeterCluster, 1); - - private: - - /** An array of references to the hits associated withi this cluster. */ - TRefArray* hits_{new TRefArray{}}; - - /** A reference to the seed hit of this cluster. */ - TRef seed_hit_; - - /** The number of hits composing this cluster. */ - int n_hits_{0}; - - /** The x position of the cluster in (mm). */ - double x_{-9999}; - - /** The y position of the cluster in (mm). */ - double y_{-9999}; - - /** The z position of the cluster in (mm). */ - double z_{-9999}; - - /** The energy of the cluster in GeV. */ - double energy_{-9999}; - - /** The cluster time. */ - double time_{-9999}; - -}; // CalorimeterCluster - -#endif // _CALORIMETER_CLUSTER_H_ diff --git a/event/include/CalorimeterHit.h b/event/include/CalorimeterHit.h deleted file mode 100644 index a3208a3bf..000000000 --- a/event/include/CalorimeterHit.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file CalorimeterHit.h - * @brief Class that encapsulate calorimeter hit information - * @author Omar Moreno, SLAC National Accelerator Laboratory - */ - -#ifndef __CALORIMETER_HIT_H__ -#define __CALORIMETER_HIT_H__ - -//----------------// -// C++ StdLib // -//----------------// -#include - -//----------// -// ROOT // -//----------// -#include - -class CalorimeterHit : public TObject { - - public: - - /** Constructor */ - CalorimeterHit(); - - /** Destructor */ - ~CalorimeterHit(); - - /** Reset the hit object */ - void Clear(Option_t* option=""); - - /** - * Set the energy of the hit in GeV. - * - * @param energy The energy of the hit in GeV. - */ - void setEnergy(const double energy){ energy_ = energy; }; - - /** @return The energy of the hit in GeV. */ - double getEnergy() const { return energy_; }; - - /** - * Set the time of the hit in ns. - * - * @param time The time of the hit in ns. - */ - void setTime(const double time) { time_ = time; }; - - /** @return The time of the hit in ns. */ - double getTime() const { return time_; }; - - /** - * Set the indices of the crystal. - * - * @param index_x The index along x - * @param index_y The index along y - */ - void setCrystalIndices(int index_x_, int index_y_); - - /** @return The crystal indices. */ - std::vector getCrystalIndices() const { return { index_x_, index_y_ }; } - - ClassDef(CalorimeterHit, 1); - - private: - - /** The crystal index along x. */ - int index_x_{-9999}; - - /** The crystal index along y. */ - int index_y_{-9999}; - - /** The energy of the hit in GeV. */ - double energy_{-9999}; - - /** The time of the hit in ns. */ - double time_{0}; - -}; // CalorimeterHit - -#endif // _CALORIMETER_HIT_H_ diff --git a/event/src/CalorimeterCluster.cxx b/event/src/CalorimeterCluster.cxx deleted file mode 100644 index 337022d52..000000000 --- a/event/src/CalorimeterCluster.cxx +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file CalorimeterCluster.cxx - * @brief Class used to encapsulate calorimeter cluster information. - * @author Omar Moreno, SLAC National Accelerator Laboratory - */ - -#include "CalorimeterCluster.h" - -ClassImp(CalorimeterCluster) - -CalorimeterCluster::CalorimeterCluster() - : TObject() { -} - -CalorimeterCluster::~CalorimeterCluster() { - Clear(); - delete hits_; -} - -void CalorimeterCluster::Clear(Option_t* /*option*/) { - TObject::Clear(); - hits_->Delete(); - seed_hit_ = nullptr; - n_hits_ = 0; -} - -void CalorimeterCluster::setPosition(const float* position) { - x_ = position[0]; - y_ = position[1]; - z_ = position[2]; -} - -void CalorimeterCluster::addHit(TObject* hit) { - ++n_hits_; - hits_->Add(hit); -} diff --git a/event/src/CalorimeterHit.cxx b/event/src/CalorimeterHit.cxx deleted file mode 100644 index 6c9f73776..000000000 --- a/event/src/CalorimeterHit.cxx +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @file CalorimeterHit.h - * @brief Class that encapsulate calorimeter hit information - * @author Omar Moreno, SLAC National Accelerator Laboratory - */ - -#include "CalorimeterHit.h" - -ClassImp(CalorimeterHit) - -CalorimeterHit::CalorimeterHit() - : TObject() { -} - -CalorimeterHit::~CalorimeterHit() { - Clear(); -} - -void CalorimeterHit::Clear(Option_t* /* options */) { - TObject::Clear(); -} - -void CalorimeterHit::setCrystalIndices(int index_x, int index_y) { - index_x = index_x; - index_y = index_y; -} From 978cb11ce3abab19d83662f495ed98cedc11ad57 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 12 Dec 2018 15:34:50 -0800 Subject: [PATCH 048/314] Add Ecal cluster collection names. --- event/include/Collections.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/event/include/Collections.h b/event/include/Collections.h index 64bdd5c09..3d129a417 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -30,6 +30,17 @@ namespace Collections { /** Name of the collection containing Final State Particles. */ constexpr const char* FINAL_STATE_PARTICLES{"FinalStateParticles"}; + /** Name of time corrected ECal hits collection. */ + constexpr const char* ECAL_TIME_CORR_HITS{"TimeCorrEcalHits"}; + + /** Name of ECal hits collection. */ + constexpr const char* ECAL_HITS{"EcalCalHits"}; + + /** Name of ECal clusters collection. */ + constexpr const char* ECAL_CLUSTERS{"EcalClustersCorr"}; + + /** Name of collection containing "other electrons". */ + constexpr const char* OTHER_ELECTRONS{"OtherElectrons"}; } #endif // _COLLECTION_H_ From 42b103c6adfaeee19b9caf88562519e09980d097 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 12 Dec 2018 15:35:59 -0800 Subject: [PATCH 049/314] Add CalHit and CalCluster to the ROOT dictionary. --- event/include/EventDef.h | 4 ++-- event/include/EventLinkDef.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/event/include/EventDef.h b/event/include/EventDef.h index 4257a2c90..fac8d1236 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -1,6 +1,6 @@ -#include "CalorimeterCluster.h" -#include "CalorimeterHit.h" +#include "CalCluster.h" +#include "CalHit.h" #include "Event.h" #include "Particle.h" #include "Track.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 137e8a98c..83d761ac2 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -6,8 +6,8 @@ #pragma link C++ nestedclasses; -#pragma link C++ class CalorimeterCluster; -#pragma link C++ class CalorimeterHit; +#pragma link C++ class CalCluster+; +#pragma link C++ class CalHit+; #pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class TrackerHit+; From 3718a87f69383987598653490e491b5e63033963 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 13 Dec 2018 14:54:43 -0800 Subject: [PATCH 050/314] Move getters to header file. --- event/include/Particle.h | 13 ++++++------- event/src/Particle.cxx | 10 ++-------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/event/include/Particle.h b/event/include/Particle.h index 63ab901c7..7ef75e253 100644 --- a/event/include/Particle.h +++ b/event/include/Particle.h @@ -15,7 +15,6 @@ #include #include -//class EcalCluster; class Particle : public TObject { @@ -42,22 +41,22 @@ class Particle : public TObject { * @return An array of references to the tracks associated with this * particle */ - TRefArray* getTracks() const; + TRefArray* getTracks() const { return tracks_; } /** - * Add a reference to an CalorimeterCluster object. This will be used + * Add a reference to an CalCluster object. This will be used * to associated a particle with the calorimeter cluster that composes it. * - * @param ecal_cluster Ecal cluster whose reference will be added + * @param cluster Cluster whose reference will be added */ - //void addCluster(EcalCluster* ecal_cluster); + void addCluster(TObject* cluster); /** * @return An array of references to the calorimeter clusters associated * with this particle */ - //TRefArray* getClusters() const; + TRefArray* getClusters() const { return clusters_; }; /** * Add a reference to an Particle object. This will be used to @@ -73,7 +72,7 @@ class Particle : public TObject { * @return An array of references to the daughter particles associated * with this particle */ - TRefArray* getParticles() const; + TRefArray* getParticles() const { return particles_; }; /** * Set the charge of the particle. diff --git a/event/src/Particle.cxx b/event/src/Particle.cxx index 2419e9625..1f86b43f0 100644 --- a/event/src/Particle.cxx +++ b/event/src/Particle.cxx @@ -31,9 +31,9 @@ void Particle::addTrack(TObject* track) { tracks_->Add(track); } -/*void Particle::addCluster(CalorimeterCluster* cluster) { +void Particle::addCluster(TObject* cluster) { clusters_->Add(static_cast(cluster)); -}*/ +} void Particle::addParticle(Particle* particle) { ++n_daughters_; @@ -65,9 +65,3 @@ void Particle::setVertexPosition(const float* vtx_pos) { std::vector Particle::getVertexPosition() const { return { vtx_x_, vtx_y_, vtx_z_ }; } - -TRefArray* Particle::getTracks() const { return tracks_; } - -//TRefArray* Particle::getClusters() const { return clusters_; } - -TRefArray* Particle::getParticles() const { return particles_; } From 135e6ce6bc72ac2c8451223d27db49533a2978b2 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 13 Dec 2018 16:15:11 -0800 Subject: [PATCH 051/314] Add clusters and daughters to particles. --- processors/include/ParticleProcessor.h | 1 + processors/src/ParticleProcessor.cxx | 104 +++++++++++++++---------- 2 files changed, 62 insertions(+), 43 deletions(-) diff --git a/processors/include/ParticleProcessor.h b/processors/include/ParticleProcessor.h index c9c23d565..fff90400b 100644 --- a/processors/include/ParticleProcessor.h +++ b/processors/include/ParticleProcessor.h @@ -32,6 +32,7 @@ //-----------// // hpstr // //-----------// +#include "CalCluster.h" #include "Collections.h" #include "Particle.h" #include "Processor.h" diff --git a/processors/src/ParticleProcessor.cxx b/processors/src/ParticleProcessor.cxx index 86455aab4..cf4c2f280 100644 --- a/processors/src/ParticleProcessor.cxx +++ b/processors/src/ParticleProcessor.cxx @@ -33,7 +33,7 @@ void ParticleProcessor::initialize() { void ParticleProcessor::process(Event* event) { for (auto& collections : collections_) { - + // Get the collection from the event EVENT::LCCollection* lc_particles = event->getLCCollection(collections.first); @@ -93,24 +93,32 @@ void ParticleProcessor::process(Event* event) { } } - - /*for (auto const &cluster : lc_particle->getClusters()) { - - // Loop through all of the clusters in the HpsEvent and find the one - // that matches the cluster associated with the particle - for (int cluster_n = 0; cluster_n < hps_event->getNumberOfEcalClusters(); ++cluster_n) { - - // Use the cluster energy to find the match - // TODO: Verify that the cluster enegy is unique enough to find a match - if (cluster->getEnergy() == hps_event->getEcalCluster(cluster_n)->getEnergy()) { - particle->addCluster(hps_event->getEcalCluster(cluster_n)); - break; - } - } - }*/ + + for (auto const &lc_cluster : lc_particle->getClusters()) { + + std::string coll_name = Collections::ECAL_TIME_CORR_HITS; + if (!event->exists(coll_name)) coll_name = Collections::ECAL_HITS; + + // Get the collection of ECal hits from the event. + TClonesArray* clusters = event->getCollection(coll_name); + + // Loop through all of the clusters in the event and find the one + // that matches the cluster associated with the particle + for (int icluster = 0; icluster < clusters->GetEntriesFast(); ++icluster) { + + CalCluster* cluster = static_cast(clusters->At(icluster)); + // Use the cluster energy to find the match + // TODO: Verify that the cluster enegy is unique enough to find a match + if (lc_cluster->getEnergy() == cluster->getEnergy()) { + particle->addCluster(cluster); + break; + } + } + } // Only add vertex information if the particle is not a final state particle - if (collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) { + if ((collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) || + (collections.first.compare(Collections::OTHER_ELECTRONS) == 0)) { // Set the PDG ID of the particle particle->setPDG(lc_particle->getParticleIDUsed()->getPDG()); continue; @@ -123,40 +131,50 @@ void ParticleProcessor::process(Event* event) { // Set the vertex chi2 particle->setVertexFitChi2(vtx->getChi2()); - // - // If the particle has daughter particles, add the daughters to the Particle - // + // + // If the particle has daughter particles, add the daughters to the + // Particle. + // + + // Get the collection of final state particles from the event. If + // it doesn't exist, continue on to the next collection. + if (!event->exists(Collections::FINAL_STATE_PARTICLES)) continue; + + // Get the collection of final state particles from the event. + TClonesArray* fs_particles + = event->getCollection(Collections::FINAL_STATE_PARTICLES); - // Loop through all of the daughter particles associated with the particle - /*for (auto const &daughter : lc_particle->getParticles()) { + // Loop through all of the daughter particles associated with the particle + for (auto const &daughter : lc_particle->getParticles()) { - // Loop through all of the final state particles in the HpsEvent and - // find the one that matches the daughters associated with the particles - for (int d_particle_n = 0; d_particle_n < hps_event->getNumberOfParticles(HpsParticle::FINAL_STATE_PARTICLE); ++d_particle_n) { - - HpsParticle* daughter_particle - = hps_event->getParticle(HpsParticle::FINAL_STATE_PARTICLE, d_particle_n); - - // Try to find the match between a final state HpsParticle - // and ReconstructedParticle daughter. For now, use the - // momentum as the matching criterion. - // TODO: Verify that the track momentum is always unique in an event. - if (daughter->getMomentum()[0] == daughter_particle->getMomentum()[0] - && daughter->getMomentum()[1] == daughter_particle->getMomentum()[1] - && daughter->getMomentum()[2] == daughter_particle->getMomentum()[2]) { + // Loop through all of the final state particles in the event + // and find the one that matches the daughters associated with + // the particles. + for (int iparticle = 0; + iparticle < fs_particles->GetEntriesFast(); ++iparticle) { + + Particle* dparticle = static_cast(fs_particles->At(iparticle)); + + // Try to find the match between a final state particle + // and ReconstructedParticle daughter. For now, use the + // momentum as the matching criterion. + // TODO: Verify that the track momentum is always unique in an event. + if ((dparticle->getMomentum()[0] == lc_particle->getMomentum()[0]) + && (dparticle->getMomentum()[1] == lc_particle->getMomentum()[1]) + && (dparticle->getMomentum()[2] == lc_particle->getMomentum()[2])) { - particle->addParticle(daughter_particle); + particle->addParticle(dparticle); - if (daughter_particle->getTracks()->GetEntriesFast() != 0) - particle->addTrack((SvtTrack*) daughter_particle->getTracks()->At(0)); + if (dparticle->getTracks()->GetEntriesFast() != 0) + particle->addTrack(dparticle->getTracks()->At(0)); - if (daughter_particle->getClusters()->GetEntriesFast() != 0) - particle->addCluster((EcalCluster*) daughter_particle->getClusters()->At(0)); + if (dparticle->getClusters()->GetEntriesFast() != 0) + particle->addCluster(dparticle->getClusters()->At(0)); - break; + break; + } } } - }*/ } // Add the hit collection to the event From 0d6d915ed0380cd8cdbf43b8966bc54ad3a8d16f Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 13 Dec 2018 16:15:34 -0800 Subject: [PATCH 052/314] Add method to check if a collection exists. --- event/include/Event.h | 9 +++++++++ event/src/Event.cxx | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/event/include/Event.h b/event/include/Event.h index c3fd7fd19..06172dd86 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -50,6 +50,15 @@ class Event { */ TClonesArray* getCollection(const std::string name); + /** + * Checks if a collection already exist. + * + * @param name Collection name + * + * @return True if the collection exist, false otherwise. + */ + bool exists(const std::string name); + /** * Clear all of the collections in the event */ diff --git a/event/src/Event.cxx b/event/src/Event.cxx index bf6441c38..a5bc76e23 100644 --- a/event/src/Event.cxx +++ b/event/src/Event.cxx @@ -43,6 +43,15 @@ TClonesArray* Event::getCollection(const std::string name) { } } +bool Event::exists(const std::string name) { + + // Search the list of collections to find if it exist. + auto it = collections_.find(name); + + if (it == collections_.end()) return false; + else return true; +} + void Event::Clear() { for (auto& collection : collections_) { From f93e25f1e787792e95b4fcf8aed8c6a7c168f9a6 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 07:49:09 -0800 Subject: [PATCH 053/314] Add collection names. --- event/include/Collections.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/event/include/Collections.h b/event/include/Collections.h index 3d129a417..d7726b9df 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -10,10 +10,10 @@ namespace Collections { /** Name of the tracks collection. */ - constexpr const char* HPS_TRACKS{"GBLTracks"}; + constexpr const char* GBL_TRACKS{"GBLTracks"}; /** Name of the tracker hits collection. */ - constexpr const char* HPS_TRACKER_HITS{"RotatedHelicalTrackHits"}; + constexpr const char* TRACKER_HITS{"RotatedHelicalTrackHits"}; /** The name of the collection containing GBL kink data GenericObjects */ constexpr const char* KINK_DATA{"GBLKinkData"}; @@ -40,7 +40,16 @@ namespace Collections { constexpr const char* ECAL_CLUSTERS{"EcalClustersCorr"}; /** Name of collection containing "other electrons". */ - constexpr const char* OTHER_ELECTRONS{"OtherElectrons"}; + constexpr const char* OTHER_ELECTRONS{"OtherElectrons"}; + + /** Name of the collection of event headers. */ + constexpr const char* EVENT_HEADERS{"EventHeader"}; + + /** Name of trigger bank collection. */ + constexpr const char* TRIGGER_BANK{"TriggerBank"}; + + /** Name of RF hits collection. */ + constexpr const char* RF_HITS{"RFHits"}; } #endif // _COLLECTION_H_ From ea72f2deb867fcdd3f7efe9338916eadafbd642e Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 07:50:00 -0800 Subject: [PATCH 054/314] Class used to encapsulate event information. --- event/include/EventHeader.h | 336 ++++++++++++++++++++++++++++++++++++ event/src/EventHeader.cxx | 21 +++ 2 files changed, 357 insertions(+) create mode 100644 event/include/EventHeader.h create mode 100644 event/src/EventHeader.cxx diff --git a/event/include/EventHeader.h b/event/include/EventHeader.h new file mode 100644 index 000000000..50a669375 --- /dev/null +++ b/event/include/EventHeader.h @@ -0,0 +1,336 @@ +/** + * @file EventHeader.h + * @brief Class used to encapsulate event information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _EVENT_HEADER_H_ +#define _EVENT_HEADER_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include + +class EventHeader : public TObject { + + public: + + /** Constructor */ + EventHeader(); + + /** Destructor */ + ~EventHeader(); + + /** Reset the EventHeader object */ + void Clear(Option_t *option=""); + + /** + * Set the event number. + * + * @param event_number The event number. + */ + void setEventNumber(const int event_number) { event_number_ = event_number; }; + + /** @return The event number. */ + int getEventNumber() const { return event_number_; }; + + /** + * Set the event time stamp. The event time is currently the Unix time + * stamp associated with the event. + * + * @param event_time The Unix time stamp of the event. + */ + void setEventTime(const int event_time) { event_time_ = event_time; }; + + /** @return The event time. */ + int getEventTime() const { return event_time_; }; + + /** + * @param event_time The run number. + */ + void setRunNumber(const int run_number) { run_number_ = run_number; }; + + /** @return The run number. */ + int getRunNumber() const { return run_number_; }; + + /** + * @param pair0_trigger Set Flag indicating whether this event was due + * to a pair0 trigger. + */ + void setPair0Trigger(const int pair0_trigger) { + pair0_trigger_ = pair0_trigger; + }; + + /** + * Indicate whether a pair0 trigger was registered for the event. + * + * @return Returns true if a pair0 trigger was registered for the, + * false otherwise. + */ + bool isPair0Trigger() const { return pair0_trigger_ == 1; }; + + /** + * @param pair1_trigger Set Flag indicating whether this event was due + * to a pair1 trigger. + */ + void setPair1Trigger(const int pair1_trigger) { + pair1_trigger_ = pair1_trigger; + }; + + /** + * Indicate whether a pair1 trigger was registered for the event. + * + * @return Returns true if a pair1 trigger was registered for the, + * false otherwise. + */ + bool isPair1Trigger() const { return pair1_trigger_ == 1; }; + + /** + * @param pulser_trigger Set Flag indicating whether this event was due + * to a pulser trigger. + */ + void setPulserTrigger(const int pulser_trigger) { + pulser_trigger_ = pulser_trigger; + }; + + /** + * Indicate whether a pulser (random) trigger was registered for the + * event. + * + * @return Returns true if a pulser trigger was registered for the, + * false otherwise. + */ + bool isPulserTrigger() const { return pulser_trigger_ == 1; }; + + /** + * @param single0_trigger Set Flag indicating whether this event was due + * to a single0 trigger. + */ + void setSingle0Trigger(const int single0_trigger) { + single0_trigger_ = single0_trigger; + }; + + /** + * Indicate whether a single0 trigger was registered for the event. + * + * @return Returns true if a single0 trigger was registered for the, + * false otherwise. + */ + bool isSingle0Trigger() const { return single0_trigger_ == 1; }; + + /** + * @param single1_trigger Set Flag indicating whether this event was due + * to a single1 trigger. + */ + void setSingle1Trigger(const int single1_trigger) { + single1_trigger_ = single1_trigger; + }; + + /** + * Indicate whether a single1 trigger was registered for the event. + * + * @return Returns true if a single1 trigger was registered for the, + * false otherwise. + */ + bool isSingle1Trigger() const { return single1_trigger_ == 1; }; + + /** + * Set the state of the SVT bias during the event i.e. was it on or + * off? + * + * @param svt_bias_state The state of the SVT bias. It's set to 0 if + * the bias was off or 1 if it was on. + */ + void setSvtBiasState(const int svt_bias_state) { + svt_bias_state_ = svt_bias_state; + }; + + /** + * Indicate whether the SVT bias was on during the event. + * + * @return Returns true if the bias was one, false otherwise. + */ + bool isSvtBiasOn() const { return svt_bias_state_ == 1; }; + + /** + * Set the flag indicating whether the event was affected by SVT burst + * noise. + * + * @param svt_burstmode_noise Flag indicating whether an event was affected + * by SVT burst noise. It's set to 0 if it was + * or 1 if it wasn't. + */ + void setSvtBurstModeNoise(const int svt_burstmode_noise) { + svt_burstmode_noise_ = svt_burstmode_noise; + }; + + /** + * Indicates whether the event was affected by SVT burst noise. + * + * @return Returns true if the event has SVT burst noise, false + * otherwise. + */ + bool hasSvtBurstModeNoise() const { return svt_burstmode_noise_ == 0; }; + + /** + * Set the flag indicating whether the SVT headers had errors. + * + * @param svt_event_header_state Flag indicating whether the SVT event + * headers had errors. + * + */ + void setSvtEventHeaderState(const int svt_event_header_state) { + svt_event_header_state_ = svt_event_header_state; + }; + + /** + * Indicates whether the SVT event headers had errors. + * + * @return Returns true if the SVT event headers had an error, + * false otherwise. + */ + bool hasSvtEventHeaderErrors() const { return svt_event_header_state_ == 0; }; + + /** + * Set the flag indicating whether the SVT latency was correct + * during an event. + * + * @param svt_latency_state Flag indicating whether the SVT latency + * was correct during an event. + */ + void setSvtLatencyState(const int svt_latency_state) { + svt_latency_state_ = svt_latency_state; + }; + + /** + * Indicate whether the SVT latency was correct during an event. + * + * @return Returns true if the SVT latency was correct, false + * otherwise. + */ + bool isSvtLatencyGood() const { return svt_latency_state_ == 1; }; + + /** + * Set the state of indicating whether the SVT was open or closed + * during an event. + * + * @param svt_position_state The state indicating whether the SVT was + * open or closed. It's set to 0 if the SVT + * was open or 1 if it was closed. + */ + void setSvtPositionState(const int svt_position_state) { + svt_position_state_ = svt_position_state; + }; + + /** + * Indicates whether the SVT was open or closed during an event. + * + * @return Returns true if the SVT was closed, false otherwise. + */ + bool isSvtClosed() const { return svt_position_state_ == 1; }; + + + /** + * Set the event RF time. + * + * @param channel The channel from which the RF time was retrieved. + * @param rf_time The event RF time. + */ + void setRfTime(const int channel, const double rf_time) { + rf_times_[channel] = rf_time; + }; + + /** + * Get the RF time. + * + * @param channel The channel associated with the RF time. + * @return The RF time. + */ + double getRfTime(const int channel) const { return rf_times_[channel]; }; + + private: + + /** Event number */ + int event_number_{-9999}; + + /** Event time */ + double event_time_{-9999}; + + /** Run number */ + int run_number_{-9999}; + + /** + * Flag indicating that a pair0 trigger was registered. It's + * set to 1 if it was registered or 0 if it wasn't. + */ + int pair0_trigger_{0}; + + /** + * Flag indicating that a pair1 trigger was registered. It's + * set to 1 if it was registered or 0 if it wasn't. + */ + int pair1_trigger_{0}; + + /** + * Flag indicating that a pulser (random) trigger was registered. It's + * set to 1 if it was registered or 0 if it wasn't. + */ + int pulser_trigger_{0}; + + /** + * Flag indicating that a singles0 trigger was registered. It's + * set to 1 if it was registered or 0 if it wasn't. + */ + int single0_trigger_{0}; + + /** + * Flag indicating that a singles1 trigger was registered. It's + * set to 1 if it was registered or 0 if it wasn't. + */ + int single1_trigger_{0}; + + /** + * Flag indicating the state of the SVT bias. It's set to 0 if the bias + * was off or 1 if it was on. + */ + int svt_bias_state_{0}; + + /** + * Flag indicating whether the event was affected by SVT burst noise. + * It's set to 0 if the event saw burst noise or 1 if it was fine. + */ + int svt_burstmode_noise_{0}; + + /** + * Flag indicating whether the SVT event headers had an error. It's + * set to 0 if the event headers had and error, of 1 if it was errorless. + */ + int svt_event_header_state_{0}; + + /** + * Flag indicating whether the SVT latency was correct during an event. + * It's set to 0 if the latency was incorrect, 1 if it was fine. + */ + int svt_latency_state_{0}; + + /** + * Flag indicating whether the SVT was open or closed. It's set to 0 if + * the SVT was open or 1 if it was closed. + */ + int svt_position_state_{0}; + + /** The RF time */ + double rf_times_[2]; + + ClassDef(EventHeader, 1); + +}; // EventHeader + +#endif // _EVENT_HEADER_H_ + diff --git a/event/src/EventHeader.cxx b/event/src/EventHeader.cxx new file mode 100644 index 000000000..c2d5cfbaf --- /dev/null +++ b/event/src/EventHeader.cxx @@ -0,0 +1,21 @@ +/** + * @file EventHeader.cxx + * @brief Class used to encapsulate event information. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "EventHeader.h" + +ClassImp(EventHeader) + +EventHeader::EventHeader() + : TObject() { +} + +EventHeader::~EventHeader() { + Clear(); +} + +void EventHeader::Clear(Option_t* /* option */) { + TObject::Clear(); +} From 08713778cc8919f5b2a756ed8808261a9fe1b1cf Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 07:51:25 -0800 Subject: [PATCH 055/314] Processor used to write event info. --- processors/include/EventProcessor.h | 76 +++++++++++++++++ processors/src/EventProcessor.cxx | 122 ++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 processors/include/EventProcessor.h create mode 100644 processors/src/EventProcessor.cxx diff --git a/processors/include/EventProcessor.h b/processors/include/EventProcessor.h new file mode 100644 index 000000000..18bdaa1fa --- /dev/null +++ b/processors/include/EventProcessor.h @@ -0,0 +1,76 @@ +/** + * @file EventProcessor.h + * @brief Processor used to write event info. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _EVENT_HEADER_PROCESSOR_H__ +#define _EVENT_HEADER_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "EventHeader.h" +#include "Processor.h" +#include "TriggerData.h" + +class EventProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + EventProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~EventProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual void process(Event* event); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + TClonesArray* header_{nullptr}; + + +}; // EventProcessor + +#endif // _EVENT_HEADER_PROCESSOR_H__ diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx new file mode 100644 index 000000000..eba2d48fa --- /dev/null +++ b/processors/src/EventProcessor.cxx @@ -0,0 +1,122 @@ +/** + * @file EventProcessor.cxx + * @brief Processor used to write event info. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "EventProcessor.h" + +EventProcessor::EventProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +EventProcessor::~EventProcessor() { +} + +void EventProcessor::initialize() { + + header_ = new TClonesArray("EventHeader", 100000); +} + +void EventProcessor::process(Event* event) { + + EventHeader* header + = static_cast(header_->ConstructedAt(0)); + + EVENT::LCEvent* lc_event = event->getLCEvent(); + + // Set the event number + header->setEventNumber(lc_event->getEventNumber()); + + // Set the run number + header->setRunNumber(lc_event->getRunNumber()); + + // Set the trigger timestamp + header->setEventTime(lc_event->getTimeStamp()); + + // Set the SVT bias state + header->setSvtBiasState(lc_event->getParameters().getIntVal("svt_bias_good")); + + // Set the flag indicating whether the event was affected by SVT burst + // mode noise + header->setSvtBurstModeNoise(lc_event->getParameters().getIntVal("svt_burstmode_noise_good")); + + // Set the flag indicating whether the SVT latency was correct during an + // event. + header->setSvtLatencyState(lc_event->getParameters().getIntVal("svt_latency_good")); + + // Set the SVT position state + header->setSvtPositionState(lc_event->getParameters().getIntVal("svt_position_good")); + + // Set the SVT event header state + header->setSvtEventHeaderState(lc_event->getParameters().getIntVal("svt_event_header_good")); + + try { + EVENT::LCCollection* trigger_data + = static_cast(event->getLCCollection(Collections::TRIGGER_BANK)); + + for (int itrigger = 0; itrigger < trigger_data->getNumberOfElements(); ++itrigger) { + + EVENT::LCGenericObject* trigger_datum + = static_cast(trigger_data->getElementAt(itrigger)); + + if (trigger_datum->getIntVal(0) == 0xe10a) { + + TriggerData* tdata = new TriggerData(trigger_datum); + header->setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); + header->setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); + header->setPair0Trigger(static_cast(tdata->isPair0Trigger())); + header->setPair1Trigger(static_cast(tdata->isPair1Trigger())); + header->setPulserTrigger(static_cast(tdata->isPulserTrigger())); + + delete tdata; + break; + } + } + } catch(EVENT::DataNotAvailableException e) { + // It's fine if the event doesn't have a trigger bank. + } + + try { + // Get the LCIO GenericObject collection containing the RF times + EVENT::LCCollection* rf_hits + = static_cast(event->getLCCollection(Collections::RF_HITS)); + + // The collection should only have a single RFHit object per event + if (rf_hits->getNumberOfElements() > 1) { + throw std::runtime_error("[ EventProcessor ]: The collection " + + static_cast(Collections::RF_HITS) + + " doesn't have the expected number of elements."); + } + + // Loop over all the RF hits in the event and write them to the DST + for (int ihit = 0; ihit < rf_hits->getNumberOfElements(); ++ihit) { + + // Get the RF hit from the event + EVENT::LCGenericObject* rf_hit + = static_cast(rf_hits->getElementAt(ihit)); + + // An RFHit GenericObject should only have two RF times + if (rf_hit->getNDouble() != 2) { + throw std::runtime_error("[ EventProcessor ]: The collection " + + static_cast(Collections::RF_HITS) + + " has the wrong structure."); + } + + // Write the RF times to the event + for (int ichannel = 0; ichannel < rf_hit->getNDouble(); ++ichannel) { + header->setRfTime(ichannel, rf_hit->getDoubleVal(ichannel)); + } + } + } catch(EVENT::DataNotAvailableException e) { + // It's fine if the event doesn't have an RF hits collection. + } + + event->addCollection(Collections::EVENT_HEADERS, header_); + +} + +void EventProcessor::finalize() { +} + +DECLARE_PROCESSOR(EventProcessor); From 7bcacfb7411cf605b91b52f856dfae7d121f1bc3 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 08:01:02 -0800 Subject: [PATCH 056/314] Class used to decode TI information. --- event/include/TriggerData.h | 69 +++++++++++++++++++++++++++++++++++++ event/src/TriggerData.cxx | 31 +++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 event/include/TriggerData.h create mode 100644 event/src/TriggerData.cxx diff --git a/event/include/TriggerData.h b/event/include/TriggerData.h new file mode 100644 index 000000000..bdd14eba3 --- /dev/null +++ b/event/include/TriggerData.h @@ -0,0 +1,69 @@ +/** + * @file TriggerData.h + * @brief Class used to decode TI information. + * @author: Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef _TRIGGER_DATA_H_ +#define _TRIGGER_DATA_H_ + +//----------// +// LCIO // +//----------// +#include + +class TriggerData { + + public: + + /** + * Constructor + * + * @param trigger_data : The LCGenericObeject that is being used to + * store the data from the TI + */ + TriggerData(EVENT::LCGenericObject* trigger_data); + + /** @return The trigger time. */ + double getTime() const { return time_stamp; }; + + /** @return True if the event registered a single0 trigger. */ + bool isSingle0Trigger() const { return single0; }; + + /** @return True if the event registered a single1 trigger. */ + bool isSingle1Trigger() const { return single1; }; + + /** @return True if the event registered a pair0 trigger. */ + bool isPair0Trigger() const { return pair0; }; + + /** @return True if the event registered a pair1 trigger. */ + bool isPair1Trigger() const { return pair1; }; + + /** @return True if the event registered a pulser trigger. */ + bool isPulserTrigger() const { return pulser; }; + + private: + + /** Private method used to decode all trigger information. */ + void parseTriggerData(EVENT::LCGenericObject* trigger_data); + + /** Trigger time stamp. */ + long time_stamp_{-9999}; + + /** Flag indicating whether a single0 trigger was registered. */ + bool single0_{0}; + + /** Flag indicating whether a single1 trigger was registered. */ + bool single1_{0}; + + /** Flag indicating whether a pair0 trigger was registered. */ + bool pair0_{0}; + + /** Flag indicating whether a pair1 trigger was registered. */ + bool pair1_{0}; + + /** Flag indicating whether a pulser trigger was registered. */ + bool pulser_{0}; +}; + +#endif // __TRIGGER_DATA_H__ diff --git a/event/src/TriggerData.cxx b/event/src/TriggerData.cxx new file mode 100644 index 000000000..abefcc72a --- /dev/null +++ b/event/src/TriggerData.cxx @@ -0,0 +1,31 @@ +/** + * @file TriggerData.h + * @brief Class used to decode trigger information. + * @author: Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "TriggerData.h" + +TriggerData::TriggerData(EVENT::LCGenericObject* trigger_data) { + this->parseTriggerData(trigger_data); +} + +void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) { + + int trigger_data_int = trigger_data->getIntVal(1); + single0 = ((trigger_data_int >> 24) & 1) == 1; + single1 = ((trigger_data_int >> 25) & 1) == 1; + pair0 = ((trigger_data_int >> 26) & 1) == 1; + pair1 = ((trigger_data_int >> 27) & 1) == 1; + pulser = ((trigger_data_int >> 29) & 1) == 1; + + trigger_data_int = trigger_data->getIntVal(3); + long w1 = trigger_data_int & 0xffffffffL; + trigger_data_int = trigger_data->getIntVal(4); + long w2 = trigger_data_int & 0xffffffffL; + + long timelo = w1; + long timehi = (w2 & 0xffff) << 32; + + time_stamp = 4 * (timelo + timehi); +} From cf18a3aa00570e617dfe3a65f0b08ad1a393a470 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 08:01:37 -0800 Subject: [PATCH 057/314] Add method to retrieve the LCEvent. --- event/include/Event.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/event/include/Event.h b/event/include/Event.h index 06172dd86..e427cf214 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -70,6 +70,9 @@ class Event { /** Set the LCIO event. */ void setLCEvent(EVENT::LCEvent* lc_event) { lc_event_ = lc_event; }; + /** @return LCIO event. */ + EVENT::LCEvent* getLCEvent() { return lc_event_; }; + /** Get the LCIO event. */ EVENT::LCCollection* getLCCollection(std::string name) { return static_cast(lc_event_->getCollection(name)); From 9d9764376d5735c80e44226cde20b4e421454d63 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 08:02:16 -0800 Subject: [PATCH 058/314] Add EventHeader to ROOT dictionary. --- event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 1 + 2 files changed, 2 insertions(+) diff --git a/event/include/EventDef.h b/event/include/EventDef.h index fac8d1236..f90deda06 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -2,6 +2,7 @@ #include "CalCluster.h" #include "CalHit.h" #include "Event.h" +#include "EventHeader.h" #include "Particle.h" #include "Track.h" #include "TrackerHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 83d761ac2..32c22ff49 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -8,6 +8,7 @@ #pragma link C++ class CalCluster+; #pragma link C++ class CalHit+; +#pragma link C++ class EventHeader+; #pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class TrackerHit+; From 1314d68af1cded9b06de4d92be4ec6dc7a75ce32 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 08:02:55 -0800 Subject: [PATCH 059/314] Change the name of the Tracks and TrackerHits collections to match LCIO collection names. --- processors/src/ParticleProcessor.cxx | 2 +- processors/src/SvtDataProcessor.cxx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/processors/src/ParticleProcessor.cxx b/processors/src/ParticleProcessor.cxx index cf4c2f280..6ef8e8ffd 100644 --- a/processors/src/ParticleProcessor.cxx +++ b/processors/src/ParticleProcessor.cxx @@ -69,7 +69,7 @@ void ParticleProcessor::process(Event* event) { // and add references to the Particle object. for (auto const &lc_track : lc_particle->getTracks()) { - TClonesArray* tracks = event->getCollection("Tracks"); + TClonesArray* tracks = event->getCollection(Collections::GBL_TRACKS); // Loop through all of the tracks in the HpsEvent and find the one // that matches the track associated with the particle diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx index aa8fd18f0..4540646ac 100644 --- a/processors/src/SvtDataProcessor.cxx +++ b/processors/src/SvtDataProcessor.cxx @@ -19,7 +19,7 @@ void SvtDataProcessor::process(Event* event) { // Get the collection of 3D hits from the LCIO event. If no such collection // exist, a DataNotAvailableException is thrown - EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::HPS_TRACKER_HITS); + EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::TRACKER_HITS); // Create a map from an LCIO TrackerHit to a SvtHit. This will be used when // assigning references to a track @@ -58,10 +58,10 @@ void SvtDataProcessor::process(Event* event) { } // Add the hit collection to the event - event->addCollection("TrackerHits", hits_); + event->addCollection(Collections::TRACKER_HITS, hits_); // Get all track collections from the event - EVENT::LCCollection* tracks = event->getLCCollection(Collections::HPS_TRACKS); + EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); // Loop over all the LCIO Tracks and add them to the HPS event. @@ -187,7 +187,7 @@ void SvtDataProcessor::process(Event* event) { } } - event->addCollection("Tracks", tracks_); + event->addCollection(Collections::GBL_TRACKS, tracks_); } From 117a6e2f029306af0be8734375725381be38a0fb Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 08:53:55 -0800 Subject: [PATCH 060/314] Forgot to add underscores to variable names. --- event/include/TriggerData.h | 12 ++++++------ event/src/TriggerData.cxx | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/event/include/TriggerData.h b/event/include/TriggerData.h index bdd14eba3..0ca7fc741 100644 --- a/event/include/TriggerData.h +++ b/event/include/TriggerData.h @@ -25,22 +25,22 @@ class TriggerData { TriggerData(EVENT::LCGenericObject* trigger_data); /** @return The trigger time. */ - double getTime() const { return time_stamp; }; + double getTime() const { return time_stamp_; }; /** @return True if the event registered a single0 trigger. */ - bool isSingle0Trigger() const { return single0; }; + bool isSingle0Trigger() const { return single0_; }; /** @return True if the event registered a single1 trigger. */ - bool isSingle1Trigger() const { return single1; }; + bool isSingle1Trigger() const { return single1_; }; /** @return True if the event registered a pair0 trigger. */ - bool isPair0Trigger() const { return pair0; }; + bool isPair0Trigger() const { return pair0_; }; /** @return True if the event registered a pair1 trigger. */ - bool isPair1Trigger() const { return pair1; }; + bool isPair1Trigger() const { return pair1_; }; /** @return True if the event registered a pulser trigger. */ - bool isPulserTrigger() const { return pulser; }; + bool isPulserTrigger() const { return pulser_; }; private: diff --git a/event/src/TriggerData.cxx b/event/src/TriggerData.cxx index abefcc72a..72a74f0e7 100644 --- a/event/src/TriggerData.cxx +++ b/event/src/TriggerData.cxx @@ -13,11 +13,11 @@ TriggerData::TriggerData(EVENT::LCGenericObject* trigger_data) { void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) { int trigger_data_int = trigger_data->getIntVal(1); - single0 = ((trigger_data_int >> 24) & 1) == 1; - single1 = ((trigger_data_int >> 25) & 1) == 1; - pair0 = ((trigger_data_int >> 26) & 1) == 1; - pair1 = ((trigger_data_int >> 27) & 1) == 1; - pulser = ((trigger_data_int >> 29) & 1) == 1; + single0_ = ((trigger_data_int >> 24) & 1) == 1; + single1_ = ((trigger_data_int >> 25) & 1) == 1; + pair0_ = ((trigger_data_int >> 26) & 1) == 1; + pair1_ = ((trigger_data_int >> 27) & 1) == 1; + pulser_ = ((trigger_data_int >> 29) & 1) == 1; trigger_data_int = trigger_data->getIntVal(3); long w1 = trigger_data_int & 0xffffffffL; @@ -27,5 +27,5 @@ void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) { long timelo = w1; long timehi = (w2 & 0xffff) << 32; - time_stamp = 4 * (timelo + timehi); + time_stamp_ = 4 * (timelo + timehi); } From 8d8e5139187f5af217c0091ee0a674382e1ae613 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 08:56:43 -0800 Subject: [PATCH 061/314] Print event number every 1000 events. --- processing/src/Process.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 23ef8076b..5a83238c5 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -40,7 +40,8 @@ void Process::run() { // Process all events. while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { - std::cout << "--- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; + if (n_events_processed%1000 == 0) + std::cout << "--- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; event.Clear(); for (auto module : sequence_) { module->process(&event); From a299cf43b9829507434528d4a9300294b71da0dd Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 14 Dec 2018 09:00:41 -0800 Subject: [PATCH 062/314] Add config used to generate DSTs. --- processors/config/dst.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 processors/config/dst.py diff --git a/processors/config/dst.py b/processors/config/dst.py new file mode 100644 index 000000000..343fc61b3 --- /dev/null +++ b/processors/config/dst.py @@ -0,0 +1,42 @@ +# +# Configuration used to generate DST's +# + +import HpstrConf + +p = HpstrConf.Process() + +# Library containing processors +p.libraries.append("libprocessors.so") + +############################### +# Processors # +############################### + +header = HpstrConf.Processor('header', 'EventProcessor') + +svt = HpstrConf.Processor('svt', 'SvtDataProcessor') + +ecal = HpstrConf.Processor('ecal', 'ECalDataProcessor') + +particle = HpstrConf.Processor("particle", "ParticleProcessor") +particle.parameters["Collections"] = [ 'FinalStateParticles', + 'BeamspotConstrainedMollerCandidates', + 'BeamspotConstrainedV0Candidates', + 'TargetConstrainedMollerCandidates', + 'TargetConstrainedV0Candidates', + 'UnconstrainedMollerCandidates', + 'UnconstrainedV0Candidates', + 'UnconstrainedVcCandidates', + 'OtherElectrons' + ] + +# Sequence which the processors will run. +p.sequence = [header, svt, ecal, particle] + +p.input_files=['input.lcio'] +p.output_files = ['dst.root'] + +#p.max_events = 100 + +p.printProcess() From 814520edff2c11a8d31145ec4ee4dbe7298826fa Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 19 Dec 2018 18:14:47 -0800 Subject: [PATCH 063/314] Copy .pcm file to lib directory. --- event/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/event/CMakeLists.txt b/event/CMakeLists.txt index f519a441d..c055fcaa1 100644 --- a/event/CMakeLists.txt +++ b/event/CMakeLists.txt @@ -7,3 +7,6 @@ module( ) root_generate_dictionary(EventDict ${event_INCLUDE_DIR}/EventDef.h MODULE ${PROJECT_NAME} LINKDEF ${event_INCLUDE_DIR}/EventLinkDef.h) + +# install ROOT pcm file +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}_rdict.pcm DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) From c37026ffa52be3313d3b743d0e3b6fecc4c2d6ef Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 20 Dec 2018 14:17:59 -0800 Subject: [PATCH 064/314] Add method to add TObject to event. Add EventHeader as an object instead of a TClonesArray. --- event/include/Event.h | 23 ++++++++++++++++++++--- event/src/Event.cxx | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/event/include/Event.h b/event/include/Event.h index e427cf214..e7298f7ea 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -25,6 +25,12 @@ #include #include +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "EventHeader.h" + class Event { public: @@ -35,6 +41,11 @@ class Event { /** Destructor */ ~Event(); + /** + * + */ + void add(const std::string name, TObject* object); + /** * Add a collection (TClonesArray) of objects to the event. * @@ -57,12 +68,15 @@ class Event { * * @return True if the collection exist, false otherwise. */ - bool exists(const std::string name); + bool exists(const std::string name); /** * Clear all of the collections in the event */ - void Clear(); + void Clear(); + + /** @return Get a mutable copy of the EventHeader. */ + EventHeader& getEventHeaderMutable() const { return *event_header_; } /** @return The ROOT tree containing the event. */ TTree* getTree() { return tree_; } @@ -87,6 +101,9 @@ class Event { private: + /** The event headeer object (as pointer). */ + EventHeader* event_header_{nullptr}; + /** The ROOT tree containing the event. */ TTree* tree_{nullptr}; @@ -94,7 +111,7 @@ class Event { EVENT::LCEvent* lc_event_{nullptr}; /** Container with all TClonesArray collections. */ - std::map collections_; + std::map objects_; /** Container will all branches. */ std::map branches_; diff --git a/event/src/Event.cxx b/event/src/Event.cxx index a5bc76e23..fdab5acf1 100644 --- a/event/src/Event.cxx +++ b/event/src/Event.cxx @@ -10,34 +10,56 @@ Event::Event() { // Create the tree - tree_ = new TTree("HPS_Event", "HPS event tree"); + tree_ = new TTree("HPS_Event", "HPS event tree"); + + // Instantiate the event header + event_header_ = new EventHeader(); } Event::~Event() {} +void Event::add(const std::string name, TObject* object) { + + // Check if the object has been added to the event. + if (objects_.find(name) != objects_.end()) { + object->Copy(*objects_[name]); + return; + } + + // Create a clone of the object + TObject* cp = object->Clone(); + objects_[name] = cp; + + // Add a branch with the given name to the event tree. + branches_[name] = tree_->Branch(name.c_str(), cp); + + // Copy the object to the event + object->Copy(*cp); +} + void Event::addCollection(const std::string name, TClonesArray* collection) { // Check if the collection has been added - if (collections_.find(name) != collections_.end()) return; + if (objects_.find(name) != objects_.end()) return; // Add a branch with the given name to the event tree. branches_[name] = tree_->Branch(name.c_str(), collection, 1000000, 3); // Keep track of which events were added to the event - collections_[name] = collection; + objects_[name] = collection; } TClonesArray* Event::getCollection(const std::string name) { // Check if the collection already exist - auto itc = collections_.find(name); + auto itc = objects_.find(name); auto itb = branches_.find(name); - if (itc != collections_.end()) { + if (itc != objects_.end()) { if (itb != branches_.end()) { itb->second->GetEntry(entry_); } - return itc->second; + return static_cast(itc->second); } else { throw std::runtime_error("Collection not found."); } @@ -46,15 +68,15 @@ TClonesArray* Event::getCollection(const std::string name) { bool Event::exists(const std::string name) { // Search the list of collections to find if it exist. - auto it = collections_.find(name); + auto it = objects_.find(name); - if (it == collections_.end()) return false; + if (it == objects_.end()) return false; else return true; } void Event::Clear() { - for (auto& collection : collections_) { + for (auto& collection : objects_) { collection.second->Clear("C"); } } From 9b0291c8de707203c8e4d5d808d96948a2be7481 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 20 Dec 2018 14:20:16 -0800 Subject: [PATCH 065/314] Update to make of TObject instead of TClonesArray. --- processors/src/EventProcessor.cxx | 38 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index eba2d48fa..f3252a1d2 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -14,42 +14,41 @@ EventProcessor::~EventProcessor() { } void EventProcessor::initialize() { - - header_ = new TClonesArray("EventHeader", 100000); } void EventProcessor::process(Event* event) { - EventHeader* header - = static_cast(header_->ConstructedAt(0)); + /*EventHeader* header + = static_cast(header_->ConstructedAt(0));*/ + EventHeader& header = event->getEventHeaderMutable(); EVENT::LCEvent* lc_event = event->getLCEvent(); // Set the event number - header->setEventNumber(lc_event->getEventNumber()); + header.setEventNumber(lc_event->getEventNumber()); // Set the run number - header->setRunNumber(lc_event->getRunNumber()); + header.setRunNumber(lc_event->getRunNumber()); // Set the trigger timestamp - header->setEventTime(lc_event->getTimeStamp()); + header.setEventTime(lc_event->getTimeStamp()); // Set the SVT bias state - header->setSvtBiasState(lc_event->getParameters().getIntVal("svt_bias_good")); + header.setSvtBiasState(lc_event->getParameters().getIntVal("svt_bias_good")); // Set the flag indicating whether the event was affected by SVT burst // mode noise - header->setSvtBurstModeNoise(lc_event->getParameters().getIntVal("svt_burstmode_noise_good")); + header.setSvtBurstModeNoise(lc_event->getParameters().getIntVal("svt_burstmode_noise_good")); // Set the flag indicating whether the SVT latency was correct during an // event. - header->setSvtLatencyState(lc_event->getParameters().getIntVal("svt_latency_good")); + header.setSvtLatencyState(lc_event->getParameters().getIntVal("svt_latency_good")); // Set the SVT position state - header->setSvtPositionState(lc_event->getParameters().getIntVal("svt_position_good")); + header.setSvtPositionState(lc_event->getParameters().getIntVal("svt_position_good")); // Set the SVT event header state - header->setSvtEventHeaderState(lc_event->getParameters().getIntVal("svt_event_header_good")); + header.setSvtEventHeaderState(lc_event->getParameters().getIntVal("svt_event_header_good")); try { EVENT::LCCollection* trigger_data @@ -63,11 +62,11 @@ void EventProcessor::process(Event* event) { if (trigger_datum->getIntVal(0) == 0xe10a) { TriggerData* tdata = new TriggerData(trigger_datum); - header->setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); - header->setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); - header->setPair0Trigger(static_cast(tdata->isPair0Trigger())); - header->setPair1Trigger(static_cast(tdata->isPair1Trigger())); - header->setPulserTrigger(static_cast(tdata->isPulserTrigger())); + header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); + header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); + header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); + header.setPair1Trigger(static_cast(tdata->isPair1Trigger())); + header.setPulserTrigger(static_cast(tdata->isPulserTrigger())); delete tdata; break; @@ -105,15 +104,14 @@ void EventProcessor::process(Event* event) { // Write the RF times to the event for (int ichannel = 0; ichannel < rf_hit->getNDouble(); ++ichannel) { - header->setRfTime(ichannel, rf_hit->getDoubleVal(ichannel)); + header.setRfTime(ichannel, rf_hit->getDoubleVal(ichannel)); } } } catch(EVENT::DataNotAvailableException e) { // It's fine if the event doesn't have an RF hits collection. } - event->addCollection(Collections::EVENT_HEADERS, header_); - + event->add(Collections::EVENT_HEADERS, &header); } void EventProcessor::finalize() { From 2e23e2928c098ce4b43a3e3f574b9e63d9c5529d Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 21 Dec 2018 16:29:23 -0800 Subject: [PATCH 066/314] Add copy method. --- event/include/EventHeader.h | 19 +++++++++++++++---- event/src/EventHeader.cxx | 31 ++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/event/include/EventHeader.h b/event/include/EventHeader.h index 50a669375..5e97f4d71 100644 --- a/event/include/EventHeader.h +++ b/event/include/EventHeader.h @@ -10,6 +10,8 @@ //----------------// // C++ StdLib // //----------------// +#include +#include #include //----------// @@ -30,6 +32,13 @@ class EventHeader : public TObject { /** Reset the EventHeader object */ void Clear(Option_t *option=""); + /** + * Copy this object + * + * @param obj The target object. + */ + void Copy(TObject& obj) const; + /** * Set the event number. * @@ -46,10 +55,10 @@ class EventHeader : public TObject { * * @param event_time The Unix time stamp of the event. */ - void setEventTime(const int event_time) { event_time_ = event_time; }; + void setEventTime(const long event_time) { event_time_ = event_time; }; /** @return The event time. */ - int getEventTime() const { return event_time_; }; + long getEventTime() const { return event_time_; }; /** * @param event_time The run number. @@ -253,14 +262,16 @@ class EventHeader : public TObject { * @return The RF time. */ double getRfTime(const int channel) const { return rf_times_[channel]; }; - + + void Print(); + private: /** Event number */ int event_number_{-9999}; /** Event time */ - double event_time_{-9999}; + long event_time_{-9999}; /** Run number */ int run_number_{-9999}; diff --git a/event/src/EventHeader.cxx b/event/src/EventHeader.cxx index c2d5cfbaf..1ed1a2f27 100644 --- a/event/src/EventHeader.cxx +++ b/event/src/EventHeader.cxx @@ -10,7 +10,7 @@ ClassImp(EventHeader) EventHeader::EventHeader() : TObject() { -} + } EventHeader::~EventHeader() { Clear(); @@ -19,3 +19,32 @@ EventHeader::~EventHeader() { void EventHeader::Clear(Option_t* /* option */) { TObject::Clear(); } + +void EventHeader::Copy(TObject& obj) const { + + EventHeader& header = static_cast(obj); + header.event_number_ = event_number_; + header.event_time_ = event_time_; + header.run_number_ = run_number_; + header.pair0_trigger_ = pair0_trigger_; + header.pair1_trigger_ = pair1_trigger_; + header.pulser_trigger_ = pulser_trigger_; + header.single0_trigger_ = single0_trigger_; + header.single1_trigger_ = single1_trigger_; + header.svt_bias_state_ = svt_bias_state_; + header.svt_burstmode_noise_ = svt_burstmode_noise_; + header.svt_event_header_state_ = svt_event_header_state_; + header.svt_latency_state_ = svt_latency_state_; + header.svt_position_state_ = svt_position_state_; + header.rf_times_[0] = rf_times_[0]; + header.rf_times_[1] = rf_times_[1]; +} + +void EventHeader::Print() { + std::cout << "[ EventHeader ]:\n" + << "\tEvent number: " << event_number_ << "\n" + << "\tRun number: " << run_number_ << "\n" + << "\tEvent time: " << event_time_ << "\n" + << "\tRF time: 1) " << rf_times_[0] << " 2) " << rf_times_[1] + << std::endl; +} From 6f0aa25adf35359fa0df338cded3a42f36782fdb Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 21 Dec 2018 16:33:36 -0800 Subject: [PATCH 067/314] Include momentum and charge as part of the track instead of getting it from the associated reconstructed particle. --- event/include/Track.h | 34 +++++++++++++++++++++++++++++----- event/src/Track.cxx | 14 +++++--------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/event/include/Track.h b/event/include/Track.h index 291f43392..60ad05063 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -143,19 +143,30 @@ class Track : public TObject { int getType() const { return type; }; + /** + * Set the track charge. + * + * @param charge Track charge. + */ + void setCharge(const int charge) { charge_ = charge; }; + /** * Get the charge of a the track. * * @return The charge associated of the track. */ - int getCharge(); + int getCharge() const { return charge_; }; - /** - * Get the track momentum. + /** + * Set the momentum of the track. The momentum is extracted from + * the corresponding ReconstructedParticle. * - * @return The track momentum. + * @param momentum The momentum of the track. */ - std::vector getMomentum(); + void setMomentum(std::vector momentum); + + /** @return The track momentum. */ + std::vector getMomentum() { return {px_, py_, pz_}; }; /** * Set the lambda kink of the given layer. @@ -199,6 +210,11 @@ class Track : public TObject { */ bool isBottomTrack() const { return track_volume_ ? true : false; }; + /** + * @return Number of tracker hits associated with this track. + */ + int getTrackerHitCount() const { return n_hits_; }; + private: /** Reference to the 3D hits associated with this track. */ @@ -270,6 +286,14 @@ class Track : public TObject { /** Array used to store the phi kinks for each of the sensor layers. */ double phi_kinks_[12]; + /** Track momentum. */ + double px_{-9999}; + double py_{-9999}; + double pz_{-9999}; + + /** Track charge. */ + int charge_{0}; + ClassDef(Track, 1); }; // Track diff --git a/event/src/Track.cxx b/event/src/Track.cxx index b24f3f23e..f7c659bea 100644 --- a/event/src/Track.cxx +++ b/event/src/Track.cxx @@ -43,15 +43,11 @@ void Track::setPositionAtEcal(const double* position) { std::vector Track::getPositionAtEcal() { return { x_at_ecal_, y_at_ecal_, z_at_ecal_ }; } -//int Track::getCharge() { -// if (fs_particle == NULL) return 9999; -// return ((HpsParticle*) this->fs_particle.GetObject())->getCharge(); -//} - -//std::vector Track::getMomentum() { -// if (fs_particle == NULL) return {0, 0, 0}; -// return ((HpsParticle*) this->fs_particle.GetObject())->getMomentum(); -//} +void Track::setMomentum(std::vector momentum) { + px_ = momentum[0]; + py_ = momentum[1]; + pz_ = momentum[2]; +} void Track::addHit(TObject* hit) { ++n_hits_; From cea3d93ed0a112957495dfc9d9235a03da078b6d Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 21 Dec 2018 16:34:13 -0800 Subject: [PATCH 068/314] Add underscores to class variables. --- event/include/TrackerHit.h | 38 +++++++++++++------------------------- event/src/TrackerHit.cxx | 25 ++++++++++--------------- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/event/include/TrackerHit.h b/event/include/TrackerHit.h index 11590fa6a..9e46a169d 100644 --- a/event/include/TrackerHit.h +++ b/event/include/TrackerHit.h @@ -31,13 +31,6 @@ class TrackerHit : public TObject { /** Reset the Hit object. */ void Clear(Option_t *option=""); - /** - * Set the layer associated with this hit. - * - * @param layer The layer associated with this hit. - */ - void setLayer(const int layer){ this->layer = layer; }; - /** * Set the hit position. * @@ -46,7 +39,7 @@ class TrackerHit : public TObject { void setPosition(const double* position); /** @return The hit position. */ - std::vector getPosition() const; + std::vector getPosition() const { return {x_, y_, z_}; }; /** * Set the covariance matrix. @@ -63,41 +56,36 @@ class TrackerHit : public TObject { * * @param time The hit time. */ - void setTime(const double time) { this->time = time; }; - - /** @return The layer associated with this hit. */ - double getLayer() const { return layer; }; + void setTime(const double time) { time_ = time; }; /** @return The hit time. */ - double getTime() const { return time; }; + double getTime() const { return time_; }; ClassDef(TrackerHit, 1); private: /** The x position of the hit. */ - double x{-999}; + double x_{-999}; /** The x position of the hit. */ - double y{-999}; + double y_{-999}; /** The x position of the hit. */ - double z{-999}; + double z_{-999}; /** Components of the covariance matrix. */ - double cxx{0}; - double cxy{0}; - double cxz{0}; - double cyy{0}; - double cyz{0}; - double czz{0}; + double cxx_{0}; + double cxy_{0}; + double cxz_{0}; + double cyy_{0}; + double cyz_{0}; + double czz_{0}; /** The hit time. */ - double time{-999}; + double time_{-999}; - /** The hit layer. */ - int layer{0}; }; // TrackerHit diff --git a/event/src/TrackerHit.cxx b/event/src/TrackerHit.cxx index bed04ef2a..30e541b49 100644 --- a/event/src/TrackerHit.cxx +++ b/event/src/TrackerHit.cxx @@ -21,25 +21,20 @@ void TrackerHit::Clear(Option_t* /* options */) { } void TrackerHit::setPosition(const double* position) { - x = position[0]; - y = position[1]; - z = position[2]; + x_ = position[0]; + y_ = position[1]; + z_ = position[2]; } -std::vector TrackerHit::getPosition() const { - return { x, y, z }; -} - - void TrackerHit::setCovarianceMatrix(const std::vector covariance_matrix) { - cxx = covariance_matrix[0]; - cxy = covariance_matrix[1]; - cxz = covariance_matrix[2]; - cyy = covariance_matrix[3]; - cyz = covariance_matrix[4]; - czz = covariance_matrix[5]; + cxx_ = covariance_matrix[0]; + cxy_ = covariance_matrix[1]; + cxz_ = covariance_matrix[2]; + cyy_ = covariance_matrix[3]; + cyz_ = covariance_matrix[4]; + czz_ = covariance_matrix[5]; } std::vector TrackerHit::getCovarianceMatrix() const { - return { cxx, cxy, cxz, cyy, cyz, czz }; + return { cxx_, cxy_, cxz_, cyy_, cyz_, czz_ }; } From 13393bd9f6b02868516d4b6bb86b70f5c1836028 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 21 Dec 2018 16:34:32 -0800 Subject: [PATCH 069/314] Set the track momentum and charge. --- processors/src/ParticleProcessor.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/processors/src/ParticleProcessor.cxx b/processors/src/ParticleProcessor.cxx index 6ef8e8ffd..c192fa26e 100644 --- a/processors/src/ParticleProcessor.cxx +++ b/processors/src/ParticleProcessor.cxx @@ -85,8 +85,11 @@ void ParticleProcessor::process(Event* event) { // If the particle is a final state particle, add a // reference from the corresponding track to the particle - if (collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) { - track->setParticle(particle); + if ((collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) + || (collections.first.compare(Collections::OTHER_ELECTRONS) == 0) ) { + track->setParticle(particle); + track->setMomentum(particle->getMomentum()); + track->setCharge(particle->getCharge()); } break; } From 56da888ce64ed942681b4fdcb4706c3e00188584 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 21 Dec 2018 16:41:37 -0800 Subject: [PATCH 070/314] Add underscore to type --- event/include/Track.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/event/include/Track.h b/event/include/Track.h index 60ad05063..742db1507 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -137,10 +137,10 @@ class Track : public TObject { * * @param type The track type. */ - void setType(const int type) { this->type = type; }; + void setType(const int type) { type_ = type; }; /** @return The track type. */ - int getType() const { return type; }; + int getType() const { return type_; }; /** @@ -233,7 +233,7 @@ class Track : public TObject { int track_volume_{-999}; /** The track type. */ - int type{-999}; + int type_{-999}; /** The distance of closest approach to the reference point. */ double d0_{-999}; From c59c4dd904c0d3da6786de97b8e10deb48640269 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 21 Dec 2018 16:41:50 -0800 Subject: [PATCH 071/314] Fix output format. --- processing/src/Process.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 5a83238c5..520bd35cf 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -41,7 +41,7 @@ void Process::run() { // Process all events. while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { if (n_events_processed%1000 == 0) - std::cout << "--- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; + std::cout << "---- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; event.Clear(); for (auto module : sequence_) { module->process(&event); From b8b8cebe8f2e29a94aea69ec52e98f0d3fd094d6 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Fri, 21 Dec 2018 16:55:01 -0800 Subject: [PATCH 072/314] Allow users to pass lcio file name as a command line argument. --- processors/config/dst.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/processors/config/dst.py b/processors/config/dst.py index 343fc61b3..7dc05a199 100644 --- a/processors/config/dst.py +++ b/processors/config/dst.py @@ -1,8 +1,12 @@ -# -# Configuration used to generate DST's -# - import HpstrConf +import sys + +# Use the input file to set the output file name +lcio_file = sys.argv[1].strip() +root_file = '%s.root' % lcio_file[:-6] + +print 'LCIO file: %s' % lcio_file +print 'Root file: %s' % root_file p = HpstrConf.Process() @@ -13,11 +17,10 @@ # Processors # ############################### -header = HpstrConf.Processor('header', 'EventProcessor') - -svt = HpstrConf.Processor('svt', 'SvtDataProcessor') +header = HpstrConf.Processor('header', 'EventProcessor') +svt = HpstrConf.Processor('svt', 'SvtDataProcessor') -ecal = HpstrConf.Processor('ecal', 'ECalDataProcessor') +ecal = HpstrConf.Processor('ecal', 'ECalDataProcessor') particle = HpstrConf.Processor("particle", "ParticleProcessor") particle.parameters["Collections"] = [ 'FinalStateParticles', @@ -34,9 +37,9 @@ # Sequence which the processors will run. p.sequence = [header, svt, ecal, particle] -p.input_files=['input.lcio'] -p.output_files = ['dst.root'] +p.input_files=[lcio_file] +p.output_files = [root_file] -#p.max_events = 100 +#p.max_events = 1000 p.printProcess() From c5108f3d6b6a28724880ee186faa75bb8401f092 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 28 Jan 2019 17:04:51 -0800 Subject: [PATCH 073/314] Require python 2.7. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac6e4de85..0b791faee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ endif() find_package(LCIO REQUIRED) # find Python installation -find_package(PythonLibs REQUIRED) +find_package(PythonLibs 2.7 REQUIRED) message(STATUS "Python lib found at: ${PYTHON_LIBRARIES}") message(STATUS "Python include dir found at: ${PYTHON_INCLUDE_DIRS}") get_filename_component(PYTHON_LIBRARY_DIR ${PYTHON_LIBRARIES} DIRECTORY) From a361890fab64c2a0d3bba0847e4e777e208a8706 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Mon, 28 Jan 2019 17:05:25 -0800 Subject: [PATCH 074/314] Module dependencies should go first in the link list. --- cmake/Modules/MacroModule.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/MacroModule.cmake b/cmake/Modules/MacroModule.cmake index 5657eed13..f4455038f 100644 --- a/cmake/Modules/MacroModule.cmake +++ b/cmake/Modules/MacroModule.cmake @@ -108,7 +108,7 @@ macro(MODULE) # make list of libraries required by executables and test programs which includes this module's lib if (sources) - set(MODULE_BIN_LIBRARIES ${MODULE_LIBRARIES} ${MODULE_NAME}) + set(MODULE_BIN_LIBRARIES ${MODULE_NAME} ${MODULE_LIBRARIES}) else() set(MODULE_BIN_LIBRARIES ${MODULE_LIBRARIES}) endif() From 97fa21112b0dde74df9ab431bcdefd8e39e7347f Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 28 Jan 2019 18:26:25 -0800 Subject: [PATCH 075/314] Make new processor by copying SvtDataProcessor --- processors/include/SvtRawDataProcessor.h | 82 ++++++++++ processors/src/SvtRawDataProcessor.cxx | 197 +++++++++++++++++++++++ setup.sh | 2 + 3 files changed, 281 insertions(+) create mode 100644 processors/include/SvtRawDataProcessor.h create mode 100644 processors/src/SvtRawDataProcessor.cxx create mode 100644 setup.sh diff --git a/processors/include/SvtRawDataProcessor.h b/processors/include/SvtRawDataProcessor.h new file mode 100644 index 000000000..f62fbfa83 --- /dev/null +++ b/processors/include/SvtRawDataProcessor.h @@ -0,0 +1,82 @@ +/** + * + */ + +#ifndef __SVT_RAW_DATA_PROCESSOR_H__ +#define __SVT_RAW_DATA_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "Track.h" +#include "TrackerHit.h" + +class SvtRawDataProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + SvtRawDataProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~SvtRawDataProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual void process(Event* event); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Container to hold all TrackerHit objects. */ + TClonesArray* hits_{nullptr}; + + /** Container to hold all Track objects. */ + TClonesArray* tracks_{nullptr}; + + +}; // SvtRawDataProcessor + +#endif // __SVT_RAW_DATA_PROCESSOR_H__ diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx new file mode 100644 index 000000000..96e5dc09b --- /dev/null +++ b/processors/src/SvtRawDataProcessor.cxx @@ -0,0 +1,197 @@ + +#include "SvtRawDataProcessor.h" + +SvtRawDataProcessor::SvtRawDataProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +SvtRawDataProcessor::~SvtRawDataProcessor() { +} + +void SvtRawDataProcessor::initialize() { + + tracks_ = new TClonesArray("Track", 100000); + hits_ = new TClonesArray("TrackerHit", 100000); +} + +void SvtRawDataProcessor::process(Event* event) { + + + // Get the collection of 3D hits from the LCIO event. If no such collection + // exist, a DataNotAvailableException is thrown + EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::TRACKER_HITS); + + // Create a map from an LCIO TrackerHit to a SvtHit. This will be used when + // assigning references to a track + // TODO: Use an unordered map for faster access + std::map hit_map; + + // Loop over all of the 3D hits in the LCIO event and add them to the + // HPS event + for (int ihit = 0; ihit < tracker_hits->getNumberOfElements(); ++ihit) { + + // Get a 3D hit from the list of hits + EVENT::TrackerHit* lc_tracker_hit = static_cast(tracker_hits->getElementAt(ihit)); + + // Add a tracker hit to the event + TrackerHit* tracker_hit = static_cast(hits_->ConstructedAt(ihit)); + + // Rotate the position of the LCIO TrackerHit and set the position of + // the TrackerHit + double hit_position[3] = { + lc_tracker_hit->getPosition()[1], + lc_tracker_hit->getPosition()[2], + lc_tracker_hit->getPosition()[0] + }; + tracker_hit->setPosition(hit_position); + + // Set the covariance matrix of the SvtHit + tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); + + // Set the time of the SvtHit + tracker_hit->setTime(lc_tracker_hit->getTime()); + + // Map the TrackerHit object to the corresponding SvtHit object. This + // will be used later when setting references for hits on tracks. + hit_map[lc_tracker_hit] = tracker_hit; + + } + + // Add the hit collection to the event + event->addCollection(Collections::TRACKER_HITS, hits_); + + // Get all track collections from the event + EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); + + + // Loop over all the LCIO Tracks and add them to the HPS event. + for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { + + // Get a LCIO Track from the LCIO event + EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); + + // Add a track to the event + Track* track = static_cast(tracks_->ConstructedAt(itrack)); + + // Set the track parameters + track->setTrackParameters(lc_track->getD0(), + lc_track->getPhi(), + lc_track->getOmega(), + lc_track->getTanLambda(), + lc_track->getZ0()); + + // Set the track type + track->setType(lc_track->getType()); + + // Set the track fit chi^2 + track->setChi2(lc_track->getChi2()); + + // Set the position of the extrapolated track at the ECal face. The + // extrapolation uses the full 3D field map. + const EVENT::TrackState* track_state + = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); + double position_at_ecal[3] = { + track_state->getReferencePoint()[1], + track_state->getReferencePoint()[2], + track_state->getReferencePoint()[0] + }; + track->setPositionAtEcal(position_at_ecal); + + // Get the collection of LCRelations between GBL kink data variables + // (GBLKinkData) and the corresponding track. + EVENT::LCCollection* gbl_kink_data = + static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to GBLKinkData object + UTIL::LCRelationNavigator* gbl_kink_data_nav + = new UTIL::LCRelationNavigator(gbl_kink_data); + + // Get the list of GBLKinkData associated with the LCIO Track + EVENT::LCObjectVec gbl_kink_data_list + = gbl_kink_data_nav->getRelatedFromObjects(lc_track); + + // The container of GBLKinkData objects should only contain a + // single object. If not, throw an exception + if (gbl_kink_data_list.size() != 1) { + throw std::runtime_error("[ SvtRawDataProcessor ]: The collection " + + std::string(Collections::TRACK_DATA_REL) + + " has the wrong data structure."); + } + + // Get the list GBLKinkData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* gbl_kink_datum + = static_cast(gbl_kink_data_list.at(0)); + + // Set the lambda and phi kink values + for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { + track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); + track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); + } + + delete gbl_kink_data_nav; + + // Get the collection of LCRelations between track data variables + // (TrackData) and the corresponding track. + EVENT::LCCollection* track_data = static_cast( + event->getLCCollection(Collections::TRACK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to TrackData objects + UTIL::LCRelationNavigator* track_data_nav + = new UTIL::LCRelationNavigator(track_data); + + // Get the list of TrackData associated with the LCIO Track + EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); + + // The container of TrackData objects should only contain a single + // object. If not, throw an exception. + if (track_data_list.size() == 1) { + + // Get the TrackData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); + + // Check that the TrackData data structure is correct. If it's + // not, throw a runtime exception. + if (track_datum->getNDouble() != 12 || track_datum->getNFloat() != 1 + || track_datum->getNInt() != 1) { + throw std::runtime_error("[ SvtRawDataProcessor ]: The collection " + + std::string(Collections::TRACK_DATA) + + " has the wrong structure."); + } + + // Set the SvtTrack isolation values + for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { + track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); + } + + // Set the SvtTrack time + track->setTrackTime(track_datum->getFloatVal(0)); + + // Set the volume (top/bottom) in which the SvtTrack resides + track->setTrackVolume(track_datum->getIntVal(0)); + } + + delete track_data_nav; + + // Get the collection of 3D hits associated with a LCIO Track + EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); + + // Iterate through the collection of 3D hits (TrackerHit objects) + // associated with a track, find the corresponding hits in the HPS + // event and add references to the track + for (auto hit : lc_tracker_hits) { + + // Add a reference to the hit + track->addHit(hit_map[hit]); + } + } + + event->addCollection(Collections::GBL_TRACKS, tracks_); + +} + +void SvtRawDataProcessor::finalize() { +} + +DECLARE_PROCESSOR(SvtRawDataProcessor); diff --git a/setup.sh b/setup.sh new file mode 100644 index 000000000..00c5e85d8 --- /dev/null +++ b/setup.sh @@ -0,0 +1,2 @@ +#!/bin/bash +export PYTHONPATH=/data/src/hpstr/processing/python:$PYTHONPATH From 0548952797ee198d713dab8b50406824ed9e98c6 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 29 Jan 2019 15:37:04 -0800 Subject: [PATCH 076/314] Add RawSvtHit Class and fill it in the new processor --- event/include/Collections.h | 3 + event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 1 + event/include/RawSvtHit.h | 46 ++++++ event/src/RawSvtHit.cxx | 31 ++++ event/src/TrackerHit.cxx | 14 +- processors/config/rawSvtHits_cfg.py | 32 ++++ processors/include/SvtRawDataProcessor.h | 13 +- processors/src/SvtRawDataProcessor.cxx | 184 +++-------------------- 9 files changed, 146 insertions(+), 179 deletions(-) create mode 100644 event/include/RawSvtHit.h create mode 100644 event/src/RawSvtHit.cxx create mode 100644 processors/config/rawSvtHits_cfg.py diff --git a/event/include/Collections.h b/event/include/Collections.h index d7726b9df..9241017d8 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -12,6 +12,9 @@ namespace Collections { /** Name of the tracks collection. */ constexpr const char* GBL_TRACKS{"GBLTracks"}; + /** Name of the Raw tracker hits collection. */ + constexpr const char* RAW_SVT_HITS{"SVTRawTrackerHits"}; + /** Name of the tracker hits collection. */ constexpr const char* TRACKER_HITS{"RotatedHelicalTrackHits"}; diff --git a/event/include/EventDef.h b/event/include/EventDef.h index f90deda06..b534f1e82 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -6,3 +6,4 @@ #include "Particle.h" #include "Track.h" #include "TrackerHit.h" +#include "RawSvtHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 32c22ff49..6cffb6b84 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -12,5 +12,6 @@ #pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class TrackerHit+; +#pragma link C++ class RawSvtHit+; #endif diff --git a/event/include/RawSvtHit.h b/event/include/RawSvtHit.h new file mode 100644 index 000000000..d74dc1cbd --- /dev/null +++ b/event/include/RawSvtHit.h @@ -0,0 +1,46 @@ +/** + * @file RawSvtHit.h + * @brief Class used to encapsulate raw svt hit information + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef _RAW_SVT_HIT_H_ +#define _RAW_SVT_HIT_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include +#include + +class RawSvtHit : public TObject { + + public: + + /** Constructor */ + RawSvtHit(); + + /** Destructor */ + virtual ~RawSvtHit(); + + /** Reset the Hit object. */ + void Clear(); + + /** Set the adc values */ + void setADCs(int adcs[6]); + + ClassDef(RawSvtHit, 1); + + private: + + /** The raw adcs of the hit. */ + int adcs_[6]{-999,-999,-999,-999,-999,-999}; + +}; // RawSvtHit + +#endif diff --git a/event/src/RawSvtHit.cxx b/event/src/RawSvtHit.cxx new file mode 100644 index 000000000..92b746f37 --- /dev/null +++ b/event/src/RawSvtHit.cxx @@ -0,0 +1,31 @@ +/** + * @file RawSvtHit.cxx + * @brief Class used to encapsulate raw svt hit information + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#include "RawSvtHit.h" + +ClassImp(RawSvtHit) + +RawSvtHit::RawSvtHit() + : TObject() { + } + +RawSvtHit::~RawSvtHit() { + Clear(); +} + +void RawSvtHit::Clear() { + TObject::Clear(); +} + +void RawSvtHit::setADCs(int adcs[6]) { + adcs_[0] = adcs[0]; + adcs_[1] = adcs[1]; + adcs_[2] = adcs[2]; + adcs_[3] = adcs[3]; + adcs_[4] = adcs[4]; + adcs_[5] = adcs[5]; +} + diff --git a/event/src/TrackerHit.cxx b/event/src/TrackerHit.cxx index 30e541b49..7176662c5 100644 --- a/event/src/TrackerHit.cxx +++ b/event/src/TrackerHit.cxx @@ -10,7 +10,7 @@ ClassImp(TrackerHit) TrackerHit::TrackerHit() : TObject() { -} + } TrackerHit::~TrackerHit() { Clear(); @@ -27,12 +27,12 @@ void TrackerHit::setPosition(const double* position) { } void TrackerHit::setCovarianceMatrix(const std::vector covariance_matrix) { - cxx_ = covariance_matrix[0]; - cxy_ = covariance_matrix[1]; - cxz_ = covariance_matrix[2]; - cyy_ = covariance_matrix[3]; - cyz_ = covariance_matrix[4]; - czz_ = covariance_matrix[5]; + cxx_ = covariance_matrix[0]; + cxy_ = covariance_matrix[1]; + cxz_ = covariance_matrix[2]; + cyy_ = covariance_matrix[3]; + cyz_ = covariance_matrix[4]; + czz_ = covariance_matrix[5]; } std::vector TrackerHit::getCovarianceMatrix() const { diff --git a/processors/config/rawSvtHits_cfg.py b/processors/config/rawSvtHits_cfg.py new file mode 100644 index 000000000..1c00910bf --- /dev/null +++ b/processors/config/rawSvtHits_cfg.py @@ -0,0 +1,32 @@ +import HpstrConf +import sys + +# Use the input file to set the output file name +lcio_file = sys.argv[1].strip() +root_file = '%s.root' % lcio_file[:-6] +root_file = 'testRun.root' + +print 'LCIO file: %s' % lcio_file +print 'Root file: %s' % root_file + +p = HpstrConf.Process() + +# Library containing processors +p.libraries.append("libprocessors.so") + +############################### +# Processors # +############################### + +header = HpstrConf.Processor('header', 'EventProcessor') +rawsvt = HpstrConf.Processor('svt', 'SvtRawDataProcessor') + +# Sequence which the processors will run. +p.sequence = [header, rawsvt] + +p.input_files=[lcio_file] +p.output_files = [root_file] + +#p.max_events = 1000 + +p.printProcess() diff --git a/processors/include/SvtRawDataProcessor.h b/processors/include/SvtRawDataProcessor.h index f62fbfa83..223e9b254 100644 --- a/processors/include/SvtRawDataProcessor.h +++ b/processors/include/SvtRawDataProcessor.h @@ -15,9 +15,7 @@ // LCIO // //----------// #include -#include -#include -#include +#include #include #include @@ -31,8 +29,7 @@ //-----------// #include "Collections.h" #include "Processor.h" -#include "Track.h" -#include "TrackerHit.h" +#include "RawSvtHit.h" class SvtRawDataProcessor : public Processor { @@ -71,11 +68,7 @@ class SvtRawDataProcessor : public Processor { private: /** Container to hold all TrackerHit objects. */ - TClonesArray* hits_{nullptr}; - - /** Container to hold all Track objects. */ - TClonesArray* tracks_{nullptr}; - + TClonesArray* rawhits_{nullptr}; }; // SvtRawDataProcessor diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 96e5dc09b..3b78b735f 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -1,4 +1,8 @@ - +/** + * @file SvtRawDataProcessor.h + * @brief Processor used to add Raw SVT data to tree + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ #include "SvtRawDataProcessor.h" SvtRawDataProcessor::SvtRawDataProcessor(const std::string& name, Process& process) @@ -10,184 +14,40 @@ SvtRawDataProcessor::~SvtRawDataProcessor() { void SvtRawDataProcessor::initialize() { - tracks_ = new TClonesArray("Track", 100000); - hits_ = new TClonesArray("TrackerHit", 100000); + rawhits_ = new TClonesArray("RawSvtHit", 100000); } void SvtRawDataProcessor::process(Event* event) { - - // Get the collection of 3D hits from the LCIO event. If no such collection // exist, a DataNotAvailableException is thrown - EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::TRACKER_HITS); - - // Create a map from an LCIO TrackerHit to a SvtHit. This will be used when - // assigning references to a track - // TODO: Use an unordered map for faster access - std::map hit_map; + EVENT::LCCollection* raw_svt_hits = event->getLCCollection(Collections::RAW_SVT_HITS); - // Loop over all of the 3D hits in the LCIO event and add them to the + // Loop over all of the raw SVT hits in the LCIO event and add them to the // HPS event - for (int ihit = 0; ihit < tracker_hits->getNumberOfElements(); ++ihit) { + for (int ihit = 0; ihit < raw_svt_hits->getNumberOfElements(); ++ihit) { // Get a 3D hit from the list of hits - EVENT::TrackerHit* lc_tracker_hit = static_cast(tracker_hits->getElementAt(ihit)); + EVENT::TrackerRawData* rawTracker_hit = static_cast(raw_svt_hits->getElementAt(ihit)); - // Add a tracker hit to the event - TrackerHit* tracker_hit = static_cast(hits_->ConstructedAt(ihit)); + // Add a raw tracker hit to the event + RawSvtHit* rawHit = static_cast(rawhits_->ConstructedAt(ihit)); // Rotate the position of the LCIO TrackerHit and set the position of // the TrackerHit - double hit_position[3] = { - lc_tracker_hit->getPosition()[1], - lc_tracker_hit->getPosition()[2], - lc_tracker_hit->getPosition()[0] + int hit_adcs[6] = { + (int)rawTracker_hit->getADCValues().at(0), + (int)rawTracker_hit->getADCValues().at(1), + (int)rawTracker_hit->getADCValues().at(2), + (int)rawTracker_hit->getADCValues().at(3), + (int)rawTracker_hit->getADCValues().at(4), + (int)rawTracker_hit->getADCValues().at(5) }; - tracker_hit->setPosition(hit_position); - - // Set the covariance matrix of the SvtHit - tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); - - // Set the time of the SvtHit - tracker_hit->setTime(lc_tracker_hit->getTime()); - - // Map the TrackerHit object to the corresponding SvtHit object. This - // will be used later when setting references for hits on tracks. - hit_map[lc_tracker_hit] = tracker_hit; + rawHit->setADCs(hit_adcs); } - // Add the hit collection to the event - event->addCollection(Collections::TRACKER_HITS, hits_); - - // Get all track collections from the event - EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); - - - // Loop over all the LCIO Tracks and add them to the HPS event. - for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { - - // Get a LCIO Track from the LCIO event - EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); - - // Add a track to the event - Track* track = static_cast(tracks_->ConstructedAt(itrack)); - - // Set the track parameters - track->setTrackParameters(lc_track->getD0(), - lc_track->getPhi(), - lc_track->getOmega(), - lc_track->getTanLambda(), - lc_track->getZ0()); - - // Set the track type - track->setType(lc_track->getType()); - - // Set the track fit chi^2 - track->setChi2(lc_track->getChi2()); - - // Set the position of the extrapolated track at the ECal face. The - // extrapolation uses the full 3D field map. - const EVENT::TrackState* track_state - = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); - double position_at_ecal[3] = { - track_state->getReferencePoint()[1], - track_state->getReferencePoint()[2], - track_state->getReferencePoint()[0] - }; - track->setPositionAtEcal(position_at_ecal); - - // Get the collection of LCRelations between GBL kink data variables - // (GBLKinkData) and the corresponding track. - EVENT::LCCollection* gbl_kink_data = - static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); - - // Instantiate an LCRelation navigator which will allow faster access - // to GBLKinkData object - UTIL::LCRelationNavigator* gbl_kink_data_nav - = new UTIL::LCRelationNavigator(gbl_kink_data); - - // Get the list of GBLKinkData associated with the LCIO Track - EVENT::LCObjectVec gbl_kink_data_list - = gbl_kink_data_nav->getRelatedFromObjects(lc_track); - - // The container of GBLKinkData objects should only contain a - // single object. If not, throw an exception - if (gbl_kink_data_list.size() != 1) { - throw std::runtime_error("[ SvtRawDataProcessor ]: The collection " - + std::string(Collections::TRACK_DATA_REL) - + " has the wrong data structure."); - } - - // Get the list GBLKinkData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* gbl_kink_datum - = static_cast(gbl_kink_data_list.at(0)); - - // Set the lambda and phi kink values - for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { - track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); - track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); - } - - delete gbl_kink_data_nav; - - // Get the collection of LCRelations between track data variables - // (TrackData) and the corresponding track. - EVENT::LCCollection* track_data = static_cast( - event->getLCCollection(Collections::TRACK_DATA_REL)); - - // Instantiate an LCRelation navigator which will allow faster access - // to TrackData objects - UTIL::LCRelationNavigator* track_data_nav - = new UTIL::LCRelationNavigator(track_data); - - // Get the list of TrackData associated with the LCIO Track - EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); - - // The container of TrackData objects should only contain a single - // object. If not, throw an exception. - if (track_data_list.size() == 1) { - - // Get the TrackData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); - - // Check that the TrackData data structure is correct. If it's - // not, throw a runtime exception. - if (track_datum->getNDouble() != 12 || track_datum->getNFloat() != 1 - || track_datum->getNInt() != 1) { - throw std::runtime_error("[ SvtRawDataProcessor ]: The collection " - + std::string(Collections::TRACK_DATA) - + " has the wrong structure."); - } - - // Set the SvtTrack isolation values - for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { - track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); - } - - // Set the SvtTrack time - track->setTrackTime(track_datum->getFloatVal(0)); - - // Set the volume (top/bottom) in which the SvtTrack resides - track->setTrackVolume(track_datum->getIntVal(0)); - } - - delete track_data_nav; - - // Get the collection of 3D hits associated with a LCIO Track - EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); - - // Iterate through the collection of 3D hits (TrackerHit objects) - // associated with a track, find the corresponding hits in the HPS - // event and add references to the track - for (auto hit : lc_tracker_hits) { - - // Add a reference to the hit - track->addHit(hit_map[hit]); - } - } - - event->addCollection(Collections::GBL_TRACKS, tracks_); + // Add the raw hit collection to the event + event->addCollection(Collections::RAW_SVT_HITS, rawhits_); } From aa2acd467cc4606a2aed9c5220505ff49be1905e Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 29 Jan 2019 16:29:18 -0800 Subject: [PATCH 077/314] Add info to RawSvtHit to get strip location --- event/include/RawSvtHit.h | 20 ++++++++++++++++++++ event/src/RawSvtHit.cxx | 20 ++++++++++++++++++++ processors/include/SvtRawDataProcessor.h | 2 +- processors/src/SvtRawDataProcessor.cxx | 13 +++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/event/include/RawSvtHit.h b/event/include/RawSvtHit.h index d74dc1cbd..00f2d3daa 100644 --- a/event/include/RawSvtHit.h +++ b/event/include/RawSvtHit.h @@ -34,12 +34,32 @@ class RawSvtHit : public TObject { /** Set the adc values */ void setADCs(int adcs[6]); + /** Set the layer */ + void setLayer(int layer); + + /** Set the module */ + void setModule(int module); + + /** Set the sensor */ + void setSensor(int sensor); + + /** Set the side */ + void setSide(int side); + + /** Set the strip */ + void setStrip(int strip); + ClassDef(RawSvtHit, 1); private: /** The raw adcs of the hit. */ int adcs_[6]{-999,-999,-999,-999,-999,-999}; + int layer_{-999}; + int module_{-999}; + int sensor_{-999}; + int side_{-999}; + int strip_{-999}; }; // RawSvtHit diff --git a/event/src/RawSvtHit.cxx b/event/src/RawSvtHit.cxx index 92b746f37..a9dcf94b1 100644 --- a/event/src/RawSvtHit.cxx +++ b/event/src/RawSvtHit.cxx @@ -29,3 +29,23 @@ void RawSvtHit::setADCs(int adcs[6]) { adcs_[5] = adcs[5]; } +void RawSvtHit::setLayer(int layer) { + layer_ = layer; +} + +void RawSvtHit::setModule(int module) { + module_ = module; +} + +void RawSvtHit::setSensor(int sensor) { + sensor_ = sensor; +} + +void RawSvtHit::setSide(int side) { + side_ = side; +} + +void RawSvtHit::setStrip(int strip) { + strip_ = strip; +} + diff --git a/processors/include/SvtRawDataProcessor.h b/processors/include/SvtRawDataProcessor.h index 223e9b254..4152fd1d2 100644 --- a/processors/include/SvtRawDataProcessor.h +++ b/processors/include/SvtRawDataProcessor.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include //----------// // ROOT // diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 3b78b735f..567940bc4 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -22,16 +22,29 @@ void SvtRawDataProcessor::process(Event* event) { // exist, a DataNotAvailableException is thrown EVENT::LCCollection* raw_svt_hits = event->getLCCollection(Collections::RAW_SVT_HITS); + // Get decoders to read cellids + UTIL::BitField64 decoder("system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12"); + //decoder[field] returns the value + // Loop over all of the raw SVT hits in the LCIO event and add them to the // HPS event for (int ihit = 0; ihit < raw_svt_hits->getNumberOfElements(); ++ihit) { // Get a 3D hit from the list of hits EVENT::TrackerRawData* rawTracker_hit = static_cast(raw_svt_hits->getElementAt(ihit)); + //Decode the cellid + EVENT::long64 value = EVENT::long64( rawTracker_hit->getCellID0() & 0xffffffff ) | ( EVENT::long64( rawTracker_hit->getCellID1() ) << 32 ) ; + decoder.setValue(value); // Add a raw tracker hit to the event RawSvtHit* rawHit = static_cast(rawhits_->ConstructedAt(ihit)); + rawHit->setLayer(decoder["layer"]); + rawHit->setModule(decoder["module"]); + rawHit->setSensor(decoder["sensor"]); + rawHit->setSide(decoder["side"]); + rawHit->setStrip(decoder["strip"]); + // Rotate the position of the LCIO TrackerHit and set the position of // the TrackerHit int hit_adcs[6] = { From 0598b92e59612a421a0df995bab5f240c5982ab0 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 29 Jan 2019 18:09:57 -0800 Subject: [PATCH 078/314] Add get methods for data stored in RawSvtHit --- event/include/RawSvtHit.h | 18 ++++++++++++++++++ event/src/RawSvtHit.cxx | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/event/include/RawSvtHit.h b/event/include/RawSvtHit.h index 00f2d3daa..a0707db50 100644 --- a/event/include/RawSvtHit.h +++ b/event/include/RawSvtHit.h @@ -49,6 +49,24 @@ class RawSvtHit : public TObject { /** Set the strip */ void setStrip(int strip); + /** Set the adc values */ + int * getADCs(); + + /** Set the layer */ + int getLayer(); + + /** Set the module */ + int getModule(); + + /** Set the sensor */ + int getSensor(); + + /** Set the side */ + int getSide(); + + /** Set the strip */ + int getStrip(); + ClassDef(RawSvtHit, 1); private: diff --git a/event/src/RawSvtHit.cxx b/event/src/RawSvtHit.cxx index a9dcf94b1..57b30da19 100644 --- a/event/src/RawSvtHit.cxx +++ b/event/src/RawSvtHit.cxx @@ -49,3 +49,27 @@ void RawSvtHit::setStrip(int strip) { strip_ = strip; } +int * RawSvtHit::getADCs() { + return adcs_; +} + +int RawSvtHit::getLayer() { + return layer_; +} + +int RawSvtHit::getModule() { + return module_; +} + +int RawSvtHit::getSensor() { + return sensor_; +} + +int RawSvtHit::getSide() { + return side_; +} + +int RawSvtHit::getStrip() { + return strip_; +} + From dd19be9da96f168ad8ca235c5953e28fe5700e52 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Wed, 6 Feb 2019 11:27:28 -0800 Subject: [PATCH 079/314] Install python libraries in correct location. --- CMakeLists.txt | 16 ---------------- cmake/Modules/MacroModule.cmake | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b791faee..9bffb5e62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,9 +36,6 @@ include(MacroModule) # import macro for declaring external dependencies include(MacroExtDeps) -# declare list of modules with correct dependency order -#set(MODULES Event Framework DetDescr Tools EventProc SimCore SimPlugins Biasing SimApplication Configuration Detectors Ecal EventDisplay) - set(MODULES event processing processors) # build each module in the list @@ -47,10 +44,6 @@ foreach(module ${MODULES}) add_subdirectory(${module}) endforeach() -# install python init file for top-level LDMX module -#file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/python/__init__.py "# python package") -#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/python/__init__.py DESTINATION lib/python/LDMX) - # configure and generate documentation using doxygen #option(INSTALL_DOC "Set to ON to generate documentation using doxygen" OFF) #message(STATUS "Doxygen documentation: ${INSTALL_DOC}") @@ -82,14 +75,5 @@ endforeach() #endif() -# option for dumping full CMake env -option(DUMP_CMAKE_VARIABLES OFF) -if(DUMP_CMAKE_VARIABLES) - get_cmake_property(_variableNames VARIABLES) - foreach(_variableName ${_variableNames}) - message(STATUS "${_variableName}=${${_variableName}}") - endforeach() -endif() - # info message about install prefix message(STATUS "hpstr will be installed to: ${CMAKE_INSTALL_PREFIX}") diff --git a/cmake/Modules/MacroModule.cmake b/cmake/Modules/MacroModule.cmake index f4455038f..a0b51b8d8 100644 --- a/cmake/Modules/MacroModule.cmake +++ b/cmake/Modules/MacroModule.cmake @@ -147,7 +147,7 @@ macro(MODULE) endforeach() # install python scripts - set(PYTHON_INSTALL_DIR lib/python/LDMX/${MODULE_NAME}) + set(PYTHON_INSTALL_DIR lib/python) file(GLOB py_scripts "${CMAKE_CURRENT_SOURCE_DIR}/python/[!_]*.py") if (py_scripts) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/python/__init__.py "# python package") From 443cf1197b22f3f5549634c4a1375ee9b8e4f717 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 21 Mar 2019 10:08:57 -0700 Subject: [PATCH 080/314] Builder class used to create ROOT ntuples. --- processing/include/TupleBuilder.h | 91 +++++++++++++++++++++++++++++++ processing/src/TupleBuilder.cxx | 36 ++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 processing/include/TupleBuilder.h create mode 100644 processing/src/TupleBuilder.cxx diff --git a/processing/include/TupleBuilder.h b/processing/include/TupleBuilder.h new file mode 100644 index 000000000..4de039169 --- /dev/null +++ b/processing/include/TupleBuilder.h @@ -0,0 +1,91 @@ +/** + * @file TupleBuilder.h + * @brief Builder class to build ROOT ntuples. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#ifndef __TUPLE_BUILDER_H__ +#define __TUPLE_BUILDER_H__ + +#include + +//----------// +// ROOT // +//----------// +#include "TTree.h" + +//-----------// +// boost // +//-----------// +#include "boost/assign/list_of.hpp" +#include "boost/variant.hpp" +#include "boost/unordered_map.hpp" + +typedef boost::variant< short, int, float, double, long > v; + +// Forward declerations +class TTree; + +class TupleBuilder { + + public: + + enum Type { + Short, + Int, + Float, + Double, + Long, + Bool + }; + + /** Constructor */ + TupleBuilder(TTree* tree); + + /** + * Add a leaf to the root tree. + * + * @param name The leaf name + * @param type The leaf type + */ + template + TTree* add(std::string name, Type type) { + variables_[name] = T(-9999); + tree_->Branch(name.c_str(), &boost::get(variables_[name]), + (name + "/" + type_string_[type]).c_str()); + return tree_; + } + + /** + * Access a leaf in the tree. + * + * @param name The leaf name. + */ + template + void set(std::string name, T value) { + variables_[name] = value; + } + + + private: + + /** ROOT TTree used to build the tuple. */ + TTree* tree_{nullptr}; + + /** Container for variables. */ + std::map variables_; + + /** Map from Type to string representation used by ROOT. */ + boost::unordered_map type_string_ = + { + {Type::Short, "S"}, + {Type::Int, "I"}, + {Type::Float, "F"}, + {Type::Double, "D"}, + {Type::Long, "L"}, + {Type::Bool, "O"} + }; + +}; // TupleBuilder + +#endif // __TUPLE_BUILDER_H__ diff --git a/processing/src/TupleBuilder.cxx b/processing/src/TupleBuilder.cxx new file mode 100644 index 000000000..998e6049d --- /dev/null +++ b/processing/src/TupleBuilder.cxx @@ -0,0 +1,36 @@ +/** + * @file TupleBuilder.h + * @brief Builder class to build ROOT ntuples. + * @author Omar Moreno, SLAC National Accelerator Laboratory + */ + +#include "TupleBuilder.h" + +//----------// +// ROOT // +//----------// +#include "TTree.h" + +TupleBuilder::TupleBuilder(TTree* tree) : + tree_(tree) { +} + +/* +TTree* TupleBuilder::add(std::string name, Type type) { + + switch(type) { + case Short: variables_[name] = short(-9999); break; + case Int: variables_[name] = int(-9999); break; + case Float: variables_[name] = float(-9999); break; + case Double: variables_[name] = double(-9999); break; + case Long: variables_[name] = long(-9999); break; + case Bool: variables_[name] = bool(0); break; + } + + std::cout << "Old: " << variables_[name] << std::endl; + std::cout << "Old A: " << &variables_[name] << std::endl; + tree_->Branch(name.c_str(), &variables_[name], + (name + "/" + type_string_[type]).c_str()); + + return tree_; +}*/ From ed1206eb951d3d60de1ac5bc8ba4584e905a9c27 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 21 Mar 2019 10:14:27 -0700 Subject: [PATCH 081/314] Require the use of the C++14 standard. --- CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b791faee..187945579 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,17 @@ # minimum cmake version cmake_minimum_required(VERSION 3.0) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD 14) +set(CMAKE_C_STANDARD_REQUIRED ON) + + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + # find the LCIO directory if (LCIO_DIR) set(LCIO_INCLUDE_DIR "${LCIO_DIR}/include") From a998c3d646e6975cd06635fc14857e23d8003931 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 21 Mar 2019 10:21:23 -0700 Subject: [PATCH 082/314] Grant access to TTree during initialization. --- processing/include/Processor.h | 3 ++- processing/src/Process.cxx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/processing/include/Processor.h b/processing/include/Processor.h index e37bb3ddf..9ea9814ee 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -21,6 +21,7 @@ // Forward declarations class Process; class Processor; +class TTree; /** Typedef for ProcessorFactory use. */ typedef Processor* ProcessorMaker(const std::string& name, Process& process); @@ -63,7 +64,7 @@ class Processor { * action when the processing of events starts, such as * creating histograms. */ - virtual void initialize() = 0; + virtual void initialize(TTree* tree) = 0; /** * Process the event and put new data products into it. diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 520bd35cf..c6a0be749 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -33,9 +33,10 @@ void Process::run() { file->setupEvent(&event); } + TTree* tree = event.getTree(); // first, notify everyone that we are starting for (auto module : sequence_) { - module->initialize(); + module->initialize(tree); } // Process all events. From b4e97141bf73db9f716c84d011ec1630e937c915 Mon Sep 17 00:00:00 2001 From: omar-moreno Date: Thu, 21 Mar 2019 10:25:07 -0700 Subject: [PATCH 083/314] Update processors to reflect changes to initialize. --- processors/include/ECalDataProcessor.h | 5 ++++- processors/include/EventProcessor.h | 5 ++++- processors/include/ParticleProcessor.h | 5 ++++- processors/include/SvtDataProcessor.h | 5 ++++- processors/include/SvtRawDataProcessor.h | 4 +++- processors/src/ECalDataProcessor.cxx | 2 +- processors/src/EventProcessor.cxx | 2 +- processors/src/ParticleProcessor.cxx | 2 +- processors/src/SvtDataProcessor.cxx | 2 +- processors/src/SvtRawDataProcessor.cxx | 2 +- 10 files changed, 24 insertions(+), 10 deletions(-) diff --git a/processors/include/ECalDataProcessor.h b/processors/include/ECalDataProcessor.h index f5ecc828d..98f130e66 100644 --- a/processors/include/ECalDataProcessor.h +++ b/processors/include/ECalDataProcessor.h @@ -36,6 +36,9 @@ typedef long long long64; +// Forward declarations +class TTree; + class ECalDataProcessor : public Processor { public: @@ -62,7 +65,7 @@ class ECalDataProcessor : public Processor { * Callback for the Processor to take any necessary * action when the processing of events starts. */ - virtual void initialize(); + virtual void initialize(TTree* tree); /** * Callback for the Processor to take any necessary diff --git a/processors/include/EventProcessor.h b/processors/include/EventProcessor.h index 18bdaa1fa..1e3f18aa4 100644 --- a/processors/include/EventProcessor.h +++ b/processors/include/EventProcessor.h @@ -32,6 +32,9 @@ #include "Processor.h" #include "TriggerData.h" +// Forward declarations +class TTree; + class EventProcessor : public Processor { public: @@ -58,7 +61,7 @@ class EventProcessor : public Processor { * Callback for the Processor to take any necessary * action when the processing of events starts. */ - virtual void initialize(); + virtual void initialize(TTree* tree); /** * Callback for the Processor to take any necessary diff --git a/processors/include/ParticleProcessor.h b/processors/include/ParticleProcessor.h index fff90400b..5fa0991a3 100644 --- a/processors/include/ParticleProcessor.h +++ b/processors/include/ParticleProcessor.h @@ -38,6 +38,9 @@ #include "Processor.h" #include "Track.h" +// Forward declarations +class TTree; + class ParticleProcessor : public Processor { public: @@ -64,7 +67,7 @@ class ParticleProcessor : public Processor { * Callback for the Processor to take any necessary * action when the processing of events starts. */ - virtual void initialize(); + virtual void initialize(TTree* tree); /** * Process the event and put new data products into it. diff --git a/processors/include/SvtDataProcessor.h b/processors/include/SvtDataProcessor.h index f9f27710e..56194538d 100644 --- a/processors/include/SvtDataProcessor.h +++ b/processors/include/SvtDataProcessor.h @@ -34,6 +34,9 @@ #include "Track.h" #include "TrackerHit.h" +// Forward declarations +class TTree; + class SvtDataProcessor : public Processor { public: @@ -60,7 +63,7 @@ class SvtDataProcessor : public Processor { * Callback for the Processor to take any necessary * action when the processing of events starts. */ - virtual void initialize(); + virtual void initialize(TTree* tree); /** * Callback for the Processor to take any necessary diff --git a/processors/include/SvtRawDataProcessor.h b/processors/include/SvtRawDataProcessor.h index 4152fd1d2..8e119e1a1 100644 --- a/processors/include/SvtRawDataProcessor.h +++ b/processors/include/SvtRawDataProcessor.h @@ -31,6 +31,8 @@ #include "Processor.h" #include "RawSvtHit.h" +class TTree; + class SvtRawDataProcessor : public Processor { public: @@ -57,7 +59,7 @@ class SvtRawDataProcessor : public Processor { * Callback for the Processor to take any necessary * action when the processing of events starts. */ - virtual void initialize(); + virtual void initialize(TTree* tree); /** * Callback for the Processor to take any necessary diff --git a/processors/src/ECalDataProcessor.cxx b/processors/src/ECalDataProcessor.cxx index 7dfb7266d..7b95730c3 100644 --- a/processors/src/ECalDataProcessor.cxx +++ b/processors/src/ECalDataProcessor.cxx @@ -13,7 +13,7 @@ ECalDataProcessor::ECalDataProcessor(const std::string& name, Process& process) ECalDataProcessor::~ECalDataProcessor() { } -void ECalDataProcessor::initialize() { +void ECalDataProcessor::initialize(TTree* tree) { cal_hits_ = new TClonesArray("CalHit", 100000); clusters_ = new TClonesArray("CalCluster", 1000000); diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index f3252a1d2..bfe395c0d 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -13,7 +13,7 @@ EventProcessor::EventProcessor(const std::string& name, Process& process) EventProcessor::~EventProcessor() { } -void EventProcessor::initialize() { +void EventProcessor::initialize(TTree* tree) { } void EventProcessor::process(Event* event) { diff --git a/processors/src/ParticleProcessor.cxx b/processors/src/ParticleProcessor.cxx index c192fa26e..d6df37a2e 100644 --- a/processors/src/ParticleProcessor.cxx +++ b/processors/src/ParticleProcessor.cxx @@ -27,7 +27,7 @@ void ParticleProcessor::configure(const ParameterSet& parameters) { } -void ParticleProcessor::initialize() { +void ParticleProcessor::initialize(TTree* tree) { } void ParticleProcessor::process(Event* event) { diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx index 4540646ac..28ed2ef69 100644 --- a/processors/src/SvtDataProcessor.cxx +++ b/processors/src/SvtDataProcessor.cxx @@ -8,7 +8,7 @@ SvtDataProcessor::SvtDataProcessor(const std::string& name, Process& process) SvtDataProcessor::~SvtDataProcessor() { } -void SvtDataProcessor::initialize() { +void SvtDataProcessor::initialize(TTree* tree) { tracks_ = new TClonesArray("Track", 100000); hits_ = new TClonesArray("TrackerHit", 100000); diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 567940bc4..587362a4f 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -12,7 +12,7 @@ SvtRawDataProcessor::SvtRawDataProcessor(const std::string& name, Process& proce SvtRawDataProcessor::~SvtRawDataProcessor() { } -void SvtRawDataProcessor::initialize() { +void SvtRawDataProcessor::initialize(TTree* tree) { rawhits_ = new TClonesArray("RawSvtHit", 100000); } From 7a3917d3b1f4f69dc420380223b25cfa03f6e682 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Sat, 29 Jun 2019 10:34:44 -0700 Subject: [PATCH 084/314] Update RawSvtHit format --- event/include/RawSvtHit.h | 26 ++++++++++++++++++++------ event/src/RawSvtHit.cxx | 16 ++++++++++++++++ processors/src/SvtRawDataProcessor.cxx | 5 +++-- setup.sh | 3 ++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/event/include/RawSvtHit.h b/event/include/RawSvtHit.h index a0707db50..e9448e726 100644 --- a/event/include/RawSvtHit.h +++ b/event/include/RawSvtHit.h @@ -34,6 +34,12 @@ class RawSvtHit : public TObject { /** Set the adc values */ void setADCs(int adcs[6]); + /** Set the system */ + void setSystem(int system); + + /** Set the barrel */ + void setBarrel(int barrel); + /** Set the layer */ void setLayer(int layer); @@ -49,22 +55,28 @@ class RawSvtHit : public TObject { /** Set the strip */ void setStrip(int strip); - /** Set the adc values */ + /** Get the adc values */ int * getADCs(); - /** Set the layer */ + /** Get the system */ + int getSystem(); + + /** Get the barrel */ + int getBarrel(); + + /** Get the layer */ int getLayer(); - /** Set the module */ + /** Get the module */ int getModule(); - /** Set the sensor */ + /** Get the sensor */ int getSensor(); - /** Set the side */ + /** Get the side */ int getSide(); - /** Set the strip */ + /** Get the strip */ int getStrip(); ClassDef(RawSvtHit, 1); @@ -73,6 +85,8 @@ class RawSvtHit : public TObject { /** The raw adcs of the hit. */ int adcs_[6]{-999,-999,-999,-999,-999,-999}; + int system_{-999}; + int barrel_{-999}; int layer_{-999}; int module_{-999}; int sensor_{-999}; diff --git a/event/src/RawSvtHit.cxx b/event/src/RawSvtHit.cxx index 57b30da19..ebddeedd2 100644 --- a/event/src/RawSvtHit.cxx +++ b/event/src/RawSvtHit.cxx @@ -29,6 +29,14 @@ void RawSvtHit::setADCs(int adcs[6]) { adcs_[5] = adcs[5]; } +void RawSvtHit::setSystem(int system) { + system_ = system; +} + +void RawSvtHit::setBarrel(int barrel) { + barrel_ = barrel; +} + void RawSvtHit::setLayer(int layer) { layer_ = layer; } @@ -53,6 +61,14 @@ int * RawSvtHit::getADCs() { return adcs_; } +int RawSvtHit::getSystem() { + return system_; +} + +int RawSvtHit::getBarrel() { + return barrel_; +} + int RawSvtHit::getLayer() { return layer_; } diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 587362a4f..8d294cbd4 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -39,14 +39,15 @@ void SvtRawDataProcessor::process(Event* event) { // Add a raw tracker hit to the event RawSvtHit* rawHit = static_cast(rawhits_->ConstructedAt(ihit)); + rawHit->setSystem(decoder["system"]); + rawHit->setBarrel(decoder["barrel"]); rawHit->setLayer(decoder["layer"]); rawHit->setModule(decoder["module"]); rawHit->setSensor(decoder["sensor"]); rawHit->setSide(decoder["side"]); rawHit->setStrip(decoder["strip"]); - // Rotate the position of the LCIO TrackerHit and set the position of - // the TrackerHit + // Extract ADC values for this hit int hit_adcs[6] = { (int)rawTracker_hit->getADCValues().at(0), (int)rawTracker_hit->getADCValues().at(1), diff --git a/setup.sh b/setup.sh index 00c5e85d8..34c940b5c 100644 --- a/setup.sh +++ b/setup.sh @@ -1,2 +1,3 @@ #!/bin/bash -export PYTHONPATH=/data/src/hpstr/processing/python:$PYTHONPATH +#export PYTHONPATH=/data/src/hpstr/processing/python:$PYTHONPATH +export PYTHONPATH=/data/src/hpstr/install/lib/python:$PYTHONPATH From 787da2978e7d51450de840b086e156c1ea9c0f84 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 15 Aug 2019 14:36:44 -0700 Subject: [PATCH 085/314] Add params from fits to Raw SVT Hits --- event/include/Collections.h | 6 +++ event/include/RawSvtHit.h | 9 ++++ event/src/RawSvtHit.cxx | 12 ++++++ processors/include/SvtRawDataProcessor.h | 3 ++ processors/src/SvtRawDataProcessor.cxx | 52 +++++++++++++++++++++--- 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/event/include/Collections.h b/event/include/Collections.h index 9241017d8..fc189266c 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -15,6 +15,12 @@ namespace Collections { /** Name of the Raw tracker hits collection. */ constexpr const char* RAW_SVT_HITS{"SVTRawTrackerHits"}; + /** Name of the Raw tracker fit relations collection. */ + constexpr const char* RAW_SVT_HIT_FITS{"SVTFittedRawTrackerHits"}; + + /** Name of the Raw tracker fit relations collection. */ + constexpr const char* RAW_SVT_HIT_FITSP{"SVTShapeFitParameters"}; + /** Name of the tracker hits collection. */ constexpr const char* TRACKER_HITS{"RotatedHelicalTrackHits"}; diff --git a/event/include/RawSvtHit.h b/event/include/RawSvtHit.h index e9448e726..6293af650 100644 --- a/event/include/RawSvtHit.h +++ b/event/include/RawSvtHit.h @@ -31,6 +31,9 @@ class RawSvtHit : public TObject { /** Reset the Hit object. */ void Clear(); + /** Set the fit parameters */ + void setFit(double fit[5]); + /** Set the adc values */ void setADCs(int adcs[6]); @@ -55,6 +58,9 @@ class RawSvtHit : public TObject { /** Set the strip */ void setStrip(int strip); + /** Get the fit paramters */ + double * getFit(); + /** Get the adc values */ int * getADCs(); @@ -83,6 +89,7 @@ class RawSvtHit : public TObject { private: + /** The raw adcs of the hit. */ int adcs_[6]{-999,-999,-999,-999,-999,-999}; int system_{-999}; @@ -92,6 +99,8 @@ class RawSvtHit : public TObject { int sensor_{-999}; int side_{-999}; int strip_{-999}; + /** The fit parameters of the hit. */ + double fit_[5]{-999.9,-999.9,-999.9,-999.9,-999.9}; }; // RawSvtHit diff --git a/event/src/RawSvtHit.cxx b/event/src/RawSvtHit.cxx index ebddeedd2..0c87ddb2a 100644 --- a/event/src/RawSvtHit.cxx +++ b/event/src/RawSvtHit.cxx @@ -20,6 +20,14 @@ void RawSvtHit::Clear() { TObject::Clear(); } +void RawSvtHit::setFit(double fit[5]) { + fit_[0] = fit[0]; + fit_[1] = fit[1]; + fit_[2] = fit[2]; + fit_[3] = fit[3]; + fit_[4] = fit[4]; +} + void RawSvtHit::setADCs(int adcs[6]) { adcs_[0] = adcs[0]; adcs_[1] = adcs[1]; @@ -57,6 +65,10 @@ void RawSvtHit::setStrip(int strip) { strip_ = strip; } +double * RawSvtHit::getFit() { + return fit_; +} + int * RawSvtHit::getADCs() { return adcs_; } diff --git a/processors/include/SvtRawDataProcessor.h b/processors/include/SvtRawDataProcessor.h index 8e119e1a1..a27b075cc 100644 --- a/processors/include/SvtRawDataProcessor.h +++ b/processors/include/SvtRawDataProcessor.h @@ -9,6 +9,7 @@ // C++ StdLib // //-----------------// #include +#include #include //----------// @@ -18,6 +19,8 @@ #include #include #include +#include +#include //----------// // ROOT // diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 8d294cbd4..b0fc8e790 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -18,10 +18,25 @@ void SvtRawDataProcessor::initialize(TTree* tree) { } void SvtRawDataProcessor::process(Event* event) { + UTIL::LCRelationNavigator* rawTracker_hit_fits_nav; + EVENT::LCCollection* raw_svt_hit_fits; // Get the collection of 3D hits from the LCIO event. If no such collection // exist, a DataNotAvailableException is thrown EVENT::LCCollection* raw_svt_hits = event->getLCCollection(Collections::RAW_SVT_HITS); + //Check to see if fits are in the file + auto evColls = event->getLCEvent()->getCollectionNames(); + auto it = std::find (evColls->begin(), evColls->end(), Collections::RAW_SVT_HIT_FITS); + bool hasFits = true; + if(it == evColls->end()) hasFits = false; + if(hasFits) + { + raw_svt_hit_fits = event->getLCCollection(Collections::RAW_SVT_HIT_FITS); + // Heap an LCRelation navigator which will allow faster access + rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); + + } + // Get decoders to read cellids UTIL::BitField64 decoder("system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12"); //decoder[field] returns the value @@ -29,13 +44,15 @@ void SvtRawDataProcessor::process(Event* event) { // Loop over all of the raw SVT hits in the LCIO event and add them to the // HPS event for (int ihit = 0; ihit < raw_svt_hits->getNumberOfElements(); ++ihit) { - + // Get a 3D hit from the list of hits - EVENT::TrackerRawData* rawTracker_hit = static_cast(raw_svt_hits->getElementAt(ihit)); + EVENT::TrackerRawData* rawTracker_hit + = static_cast(raw_svt_hits->getElementAt(ihit)); //Decode the cellid - EVENT::long64 value = EVENT::long64( rawTracker_hit->getCellID0() & 0xffffffff ) | ( EVENT::long64( rawTracker_hit->getCellID1() ) << 32 ) ; + EVENT::long64 value = EVENT::long64( rawTracker_hit->getCellID0() & 0xffffffff ) | + ( EVENT::long64( rawTracker_hit->getCellID1() ) << 32 ) ; decoder.setValue(value); - + // Add a raw tracker hit to the event RawSvtHit* rawHit = static_cast(rawhits_->ConstructedAt(ihit)); @@ -57,12 +74,37 @@ void SvtRawDataProcessor::process(Event* event) { (int)rawTracker_hit->getADCValues().at(5) }; rawHit->setADCs(hit_adcs); - + + + if (hasFits) + { + // Get the list of fit params associated with the raw tracker hit + EVENT::LCObjectVec rawTracker_hit_fits_list + = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); + + // Get the list SVTFittedRawTrackerHit GenericObject associated with the SVTRawTrackerHit + IMPL::LCGenericObjectImpl* hit_fit_param + = static_cast(rawTracker_hit_fits_list.at(0)); + + double fit_params[5] = { + (double)hit_fit_param->getDoubleVal(0), + (double)hit_fit_param->getDoubleVal(1), + (double)hit_fit_param->getDoubleVal(2), + (double)hit_fit_param->getDoubleVal(3), + (double)hit_fit_param->getDoubleVal(4) + }; + + rawHit->setFit(fit_params); + } + } // Add the raw hit collection to the event event->addCollection(Collections::RAW_SVT_HITS, rawhits_); + //Clean up + if (hasFits) delete rawTracker_hit_fits_nav; + } void SvtRawDataProcessor::finalize() { From 41f9afe031351576f05b9764c85a7b538fbc6bea Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 19 Aug 2019 16:10:30 -0700 Subject: [PATCH 086/314] Add hits for new svt layers for 2019 --- processors/src/SvtDataProcessor.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx index 28ed2ef69..d739e63f0 100644 --- a/processors/src/SvtDataProcessor.cxx +++ b/processors/src/SvtDataProcessor.cxx @@ -153,7 +153,7 @@ void SvtDataProcessor::process(Event* event) { // Check that the TrackData data structure is correct. If it's // not, throw a runtime exception. - if (track_datum->getNDouble() != 12 || track_datum->getNFloat() != 1 + if (track_datum->getNDouble() != 14 || track_datum->getNFloat() != 1 || track_datum->getNInt() != 1) { throw std::runtime_error("[ SvtDataProcessor ]: The collection " + std::string(Collections::TRACK_DATA) From 05d5db322c2cb87d4abbf99f740f5b1e6007fd91 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 19 Aug 2019 17:39:04 -0700 Subject: [PATCH 087/314] Add cluster charge deposits to TrackerHit --- event/include/TrackerHit.h | 15 ++++++++++++++- processors/include/SvtDataProcessor.h | 1 + processors/src/SvtDataProcessor.cxx | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/event/include/TrackerHit.h b/event/include/TrackerHit.h index 9e46a169d..8917c8ea9 100644 --- a/event/include/TrackerHit.h +++ b/event/include/TrackerHit.h @@ -58,10 +58,20 @@ class TrackerHit : public TObject { */ void setTime(const double time) { time_ = time; }; - /** @return The hit time. */ double getTime() const { return time_; }; + /** + * Set the hit charge deposit. + * + * @param charge The hit charge. + */ + void setCharge(const double charge) { charge_ = charge; }; + + + /** @return The hit time. */ + double getCharge() const { return charge_; }; + ClassDef(TrackerHit, 1); private: @@ -86,6 +96,9 @@ class TrackerHit : public TObject { /** The hit time. */ double time_{-999}; + /** The hit charge deposit. */ + double charge_{-999}; + }; // TrackerHit diff --git a/processors/include/SvtDataProcessor.h b/processors/include/SvtDataProcessor.h index 56194538d..c0d80d177 100644 --- a/processors/include/SvtDataProcessor.h +++ b/processors/include/SvtDataProcessor.h @@ -19,6 +19,7 @@ #include #include #include +#include #include //----------// diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx index d739e63f0..4d17faf11 100644 --- a/processors/src/SvtDataProcessor.cxx +++ b/processors/src/SvtDataProcessor.cxx @@ -31,7 +31,7 @@ void SvtDataProcessor::process(Event* event) { for (int ihit = 0; ihit < tracker_hits->getNumberOfElements(); ++ihit) { // Get a 3D hit from the list of hits - EVENT::TrackerHit* lc_tracker_hit = static_cast(tracker_hits->getElementAt(ihit)); + IMPL::TrackerHitImpl* lc_tracker_hit = static_cast(tracker_hits->getElementAt(ihit)); // Add a tracker hit to the event TrackerHit* tracker_hit = static_cast(hits_->ConstructedAt(ihit)); @@ -51,6 +51,9 @@ void SvtDataProcessor::process(Event* event) { // Set the time of the SvtHit tracker_hit->setTime(lc_tracker_hit->getTime()); + // Set the charge of the SvtHit + tracker_hit->setCharge(lc_tracker_hit->getEDep()); + // Map the TrackerHit object to the corresponding SvtHit object. This // will be used later when setting references for hits on tracks. hit_map[lc_tracker_hit] = tracker_hit; From 844931ffbc95ddf1a8ae9e660a34a688f0fb4db0 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Wed, 21 Aug 2019 15:43:52 -0700 Subject: [PATCH 088/314] Fixed compilation on MacOsX --- CMakeLists.txt | 10 ++++++++++ cmake/Modules/MacroModule.cmake | 2 +- processing/include/ParameterSet.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 750623026..1c4978b1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,21 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3") # find the LCIO directory if (LCIO_DIR) set(LCIO_INCLUDE_DIR "${LCIO_DIR}/include") + + #TEMPORARY: if MacOs LCIO standard compilation creates dynamic libs. Correct for that. + if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(LCIO_LIBRARY "${LCIO_DIR}/lib/liblcio.dylib") + else() set(LCIO_LIBRARY "${LCIO_DIR}/lib/liblcio.so") + endif() + + if (NOT EXISTS "${LCIO_DIR}") message(FATAL_ERROR "Unable to find LCIO library") endif() message(STATUS "LCIO dir set to: ${LCIO_DIR}") + + #The following are not necessary - should clean up message(STATUS "LCIO include dir set to: ${LCIO_INCLUDE_DIR}") message(STATUS "LCIO library set to: ${LCIO_LIBRARY}") endif() diff --git a/cmake/Modules/MacroModule.cmake b/cmake/Modules/MacroModule.cmake index a0b51b8d8..53e4566ac 100644 --- a/cmake/Modules/MacroModule.cmake +++ b/cmake/Modules/MacroModule.cmake @@ -99,7 +99,7 @@ macro(MODULE) add_library(${MODULE_NAME} SHARED ${sources} ${MODULE_EXTRA_SOURCES}) # add link libs - target_link_libraries(${MODULE_NAME} ${MODULE_EXTRA_LINK_LIBRARIES}) + target_link_libraries(${MODULE_NAME} ${MODULE_LIBRARIES} ${MODULE_EXTRA_LINK_LIBRARIES}) # install the library install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) diff --git a/processing/include/ParameterSet.h b/processing/include/ParameterSet.h index f2c666fe8..ca0867504 100644 --- a/processing/include/ParameterSet.h +++ b/processing/include/ParameterSet.h @@ -13,6 +13,7 @@ #include #include #include +#include class ParameterSet { From 73d4a67043c607aa585493f9a8fe3265d101b79e Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 22 Aug 2019 17:25:45 -0700 Subject: [PATCH 089/314] Fix isolation lenght for 2019 tracker. --- event/include/Track.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/event/include/Track.h b/event/include/Track.h index 742db1507..4afc215cc 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -223,8 +223,8 @@ class Track : public TObject { /** Reference to the reconstructed particle associated with this track. */ TRef particle_; - /** Array used to store the isolation variables for each of the sensor layers. */ - double isolation_[12]; + /** Array used to store the isolation variables for each of the sensor layers. Updated to 2019 geometry. */ + double isolation_[14]; /** The number of 3D hits associated with this track. */ int n_hits_{0}; From df58d7181d7fdf0cdc3a74ec98384527ae564c0a Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 29 Aug 2019 16:33:20 -0700 Subject: [PATCH 090/314] Support for extra output files. --- event/include/Track.h | 3 +++ event/include/TrackerHit.h | 5 +++++ event/src/Track.cxx | 5 +++++ processing/include/EventFile.h | 10 +++++++++- processing/src/EventFile.cxx | 7 ++++++- processing/src/Process.cxx | 7 +++++++ 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/event/include/Track.h b/event/include/Track.h index 4afc215cc..3f4f53c49 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -44,6 +44,9 @@ class Track : public TObject { /** @return A reference to the hits associated with this track. */ TRefArray* getSvtHits() const { return tracker_hits_; }; + /** @return Number of 3D hits associated with this track */ + int getNSvtHits() const { return n_hits_;} + /** * Set the track parameters. * diff --git a/event/include/TrackerHit.h b/event/include/TrackerHit.h index 8917c8ea9..5ce806ae9 100644 --- a/event/include/TrackerHit.h +++ b/event/include/TrackerHit.h @@ -38,9 +38,14 @@ class TrackerHit : public TObject { */ void setPosition(const double* position); + //TODO: stupid to return a vector. /** @return The hit position. */ std::vector getPosition() const { return {x_, y_, z_}; }; + double getGlobalX() const {return x_;} + double getGlobalY() const {return y_;} + double getGlobalZ() const {return z_;} + /** * Set the covariance matrix. * diff --git a/event/src/Track.cxx b/event/src/Track.cxx index f7c659bea..c42bc65d6 100644 --- a/event/src/Track.cxx +++ b/event/src/Track.cxx @@ -31,6 +31,11 @@ void Track::setTrackParameters(double d0, double phi0, double omega, omega_ = omega; tan_lambda_ = tan_lambda; z0_ = z0; + if (omega_ < 0) + charge_ = -1; + else + charge_ = 1; + } std::vector Track::getTrackParameters() { return { d0_, phi0_, omega_, tan_lambda_, z0_ }; } diff --git a/processing/include/EventFile.h b/processing/include/EventFile.h index 9efe04953..da748a9b5 100644 --- a/processing/include/EventFile.h +++ b/processing/include/EventFile.h @@ -30,7 +30,7 @@ class EventFile { public: /** Constructor */ - EventFile(const std::string ifilename, const std::string ofilename); + EventFile(const std::string ifilename, const std::string& ofilename); /** Destructor */ ~EventFile(); @@ -54,11 +54,19 @@ class EventFile { */ void close(); + /** + * Get output file directory + */ + void resetOutputFileDir(); + private: /** The ROOT file to which event data will be written to. */ TFile* ofile_{nullptr}; + /** Additional output files, i.e. for histogramming */ + //std::vector outputs_f; + /** Object used to build the HPS event model. */ Event* event_{nullptr}; diff --git a/processing/src/EventFile.cxx b/processing/src/EventFile.cxx index 30d787730..106ff3c89 100644 --- a/processing/src/EventFile.cxx +++ b/processing/src/EventFile.cxx @@ -6,7 +6,7 @@ #include "EventFile.h" -EventFile::EventFile(const std::string ifilename, const std::string ofilename) { +EventFile::EventFile(const std::string ifilename, const std::string& ofilename) { // Open the input LCIO file. If the input file can't be opened, throw an // exception. @@ -40,12 +40,17 @@ void EventFile::setupEvent(Event* event) { entry_ = 0; } +void EventFile::resetOutputFileDir() { + ofile_->cd(); +} + void EventFile::close() { // Close the LCIO file that was being processed lc_reader_->close(); // Write the ROOT tree to disk + ofile_->cd(); event_->getTree()->Write(); // Close the ROOT file diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index c6a0be749..87aee80f8 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -5,6 +5,7 @@ */ #include "Process.h" +#include "EventFile.h" Process::Process() {} @@ -26,6 +27,9 @@ void Process::run() { std::cout << "---- [ hpstr ][ Process ]: Processing file " << ifile << std::endl; + + //TODO:: Change the order here. + // Open the output file if an output file path has been specified. EventFile* file{nullptr}; if (!output_files_.empty()) { @@ -39,6 +43,9 @@ void Process::run() { module->initialize(tree); } + //In the case of additional output files from the processors this restores the correct ProcessID storage + file->resetOutputFileDir(); + // Process all events. while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { if (n_events_processed%1000 == 0) From 38bd1fe824ede41dc1b1af88f4439cf819a152d6 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 29 Aug 2019 16:43:32 -0700 Subject: [PATCH 091/314] Moved dependence on EventFile to src file for Process --- processing/include/Process.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/include/Process.h b/processing/include/Process.h index 2119b2168..5bd7d77c8 100644 --- a/processing/include/Process.h +++ b/processing/include/Process.h @@ -23,7 +23,7 @@ // hpstr // //-----------// #include "Processor.h" -#include "EventFile.h" + class Process { From 8797c5e8c94fb1f15e81d55bf43f5b87da3895b8 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Fri, 30 Aug 2019 15:34:42 -0700 Subject: [PATCH 092/314] Rewrote hpstr to run on both LCIO and ROOT files by a switch on executable. Added example processors for ROOT ntuple processing --- CMakeLists.txt | 2 +- analysis/CMakeLists.txt | 8 + analysis/include/ClusterHistos.h | 36 ++++ analysis/include/HistoManager.h | 97 +++++++++ analysis/src/ClusterHistos.cxx | 70 +++++++ analysis/src/HistoManager.cxx | 206 +++++++++++++++++++ analysis/src/runAnalysis.cxx | 42 ++++ event/include/Event.h | 5 +- event/include/HpsEvent.h | 22 ++ event/include/IEvent.h | 17 ++ event/src/HpsEvent.cxx | 6 + processing/include/EventFile.h | 10 +- processing/include/HpsEventFile.h | 38 ++++ processing/include/IEventFile.h | 18 ++ processing/include/Process.h | 4 + processing/include/Processor.h | 6 +- processing/src/EventFile.cxx | 4 +- processing/src/HpsEventFile.cxx | 41 ++++ processing/src/Process.cxx | 51 ++++- processing/src/hpstr.cxx | 14 +- processors/CMakeLists.txt | 2 +- processors/include/ClusterOnTrackProcessor.h | 44 ++++ processors/include/ECalDataProcessor.h | 2 +- processors/include/EventProcessor.h | 3 +- processors/include/HPSEventProcessor.h | 28 +++ processors/include/ParticleProcessor.h | 3 +- processors/include/SvtDataProcessor.h | 3 +- processors/include/SvtRawDataProcessor.h | 3 +- processors/src/ClusterOnTrackProcessor.cxx | 33 +++ processors/src/ECalDataProcessor.cxx | 8 +- processors/src/EventProcessor.cxx | 6 +- processors/src/HPSEventProcessor.cxx | 26 +++ processors/src/ParticleProcessor.cxx | 3 +- processors/src/SvtDataProcessor.cxx | 3 +- processors/src/SvtRawDataProcessor.cxx | 4 +- 35 files changed, 840 insertions(+), 28 deletions(-) create mode 100644 analysis/CMakeLists.txt create mode 100644 analysis/include/ClusterHistos.h create mode 100644 analysis/include/HistoManager.h create mode 100644 analysis/src/ClusterHistos.cxx create mode 100644 analysis/src/HistoManager.cxx create mode 100644 analysis/src/runAnalysis.cxx create mode 100644 event/include/HpsEvent.h create mode 100644 event/include/IEvent.h create mode 100644 event/src/HpsEvent.cxx create mode 100644 processing/include/HpsEventFile.h create mode 100644 processing/include/IEventFile.h create mode 100644 processing/src/HpsEventFile.cxx create mode 100644 processors/include/ClusterOnTrackProcessor.h create mode 100644 processors/include/HPSEventProcessor.h create mode 100644 processors/src/ClusterOnTrackProcessor.cxx create mode 100644 processors/src/HPSEventProcessor.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c4978b1d..05e0fa533 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ include(MacroModule) # import macro for declaring external dependencies include(MacroExtDeps) -set(MODULES event processing processors) +set(MODULES event analysis processing processors) # build each module in the list foreach(module ${MODULES}) diff --git a/analysis/CMakeLists.txt b/analysis/CMakeLists.txt new file mode 100644 index 000000000..1cb8e5643 --- /dev/null +++ b/analysis/CMakeLists.txt @@ -0,0 +1,8 @@ + +# Declare analysis module +module( + NAME analysis + EXECUTABLES ./src/runAnalysis.cxx + DEPENDENCIES event + EXTERNAL_DEPENDENCIES ROOT +) diff --git a/analysis/include/ClusterHistos.h b/analysis/include/ClusterHistos.h new file mode 100644 index 000000000..597347754 --- /dev/null +++ b/analysis/include/ClusterHistos.h @@ -0,0 +1,36 @@ +#ifndef CLUSTERHISTOS_H +#define CLUSTERHISTOS_H + +#include "TFile.h" +#include "HistoManager.h" + +#include "TrackerHit.h" + +#include + + +class ClusterHistos : public HistoManager{ + + public: + ClusterHistos(const std::string& inputName):HistoManager(inputName) + {m_name = inputName; + } + + virtual void Define3DHistos(){}; + virtual void Define2DHistos(); + virtual void Define1DHistos(); + + //virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder=""); + + + void FillHistograms(TrackerHit* hit,float weight = 1.); + //void BuildAxesMap(); + + + private: + + +}; + + +#endif diff --git a/analysis/include/HistoManager.h b/analysis/include/HistoManager.h new file mode 100644 index 000000000..dd07e8d7b --- /dev/null +++ b/analysis/include/HistoManager.h @@ -0,0 +1,97 @@ +#ifndef HISTOMANAGER_H +#define HISTOMANAGER_H + +#include "TH3.h" +#include "TH2.h" +#include "TH1.h" +#include "TFile.h" +#include "TDirectoryFile.h" +#include +#include +#include + +class HistoManager { + + public: + HistoManager() {m_name = "default";} + HistoManager(const std::string& inputName) {m_name=inputName;}; + + //Todo add proper delete!! + virtual ~HistoManager(){}; + + TH3F* get3dHisto(const std::string& str) { + return histos3d[str]; + } + + TH2F* get2dHisto(const std::string& str) { + return histos2d[str]; + } + + TH1F* get1dHisto(const std::string& str) { + return histos1d[str]; + } + + TH1F* plot1D(const std::string& name,const std::string& xtitle, int nbinsX, float xmin, float xmax); + + TH1F* plot1D(const std::string& name,const std::string& xtitle, int nbinsX, double* axisX); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, const double* axisX, + std::string ytitle, int nbinsY, const double* axisY); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, float ymin, float ymax); + + TH3F* plot3D(std::string name, + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax, + std::string ztitle, int nbinsZ, float zmin, float zmax); + + + TH3F* plot3D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY, + std::string ztitle, int nbinsZ, double* axisZ); + + + virtual void Define3DHistos(){}; + virtual void Define2DHistos(){}; + virtual void Define1DHistos(){}; + + + virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder = ""); + + virtual void saveHistos(TFile* outF,std::string folder); + + virtual void sumw2(); + + protected: + + std::string m_name; + + std::map > Axes; + + std::map histos1d; + typedef std::map::iterator it1d; + + std::map histos2d; + typedef std::map::iterator it2d; + + std::map histos3d; + typedef std::map::iterator it3d; + + + +}; + + +#endif diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx new file mode 100644 index 000000000..9bc5aabfa --- /dev/null +++ b/analysis/src/ClusterHistos.cxx @@ -0,0 +1,70 @@ +#include "ClusterHistos.h" +#include + +void ClusterHistos::Define1DHistos() { + + //TODO improve this naming scheme + std::string h_name = ""; + + //Cluster position + histos1d[m_name+"_gz"] = plot1D(m_name+"_gz", + "Global Z [mm]",20000,-1000,2000); + + histos1d[m_name+"_rot1gz"] = plot1D(m_name+"_rot1gz", + "Global Z [mm]",20000,-1000,2000); + + + histos1d[m_name+"_rot2gz"] = plot1D(m_name+"_rot2gz", + "Global Z [mm]",20000,-1000,2000); + + + + histos1d[m_name+"_charge"] = plot1D(m_name+"_edep", + "edep",30,0,3e-5); +} + + +void ClusterHistos::Define2DHistos() { + std::string h_name = ""; + + histos2d[m_name+"_charge_vs_gx"] = plot2D(m_name+"_charge_vs_gx", + "Global X [mm] ",100,0,100, + "edep",30,0,3e-5); + + int nbins = 1000; + float pitch = 0.055; + + histos2d[m_name+"_charge_vs_gy"] = plot2D(m_name+"_charge_vs_gy", + "Gloabl Y [mm]",nbins,0.750,(nbins+1)*0.055, + "edep",30,0,3e-5); +} + +void ClusterHistos::FillHistograms(TrackerHit* hit,float weight) { + + + float rotz1 = -hit->getGlobalX() * sin(30.5e-3) + hit->getGlobalZ()*cos(30.5e-3); + float rotz2 = hit->getGlobalX() * sin(30.5e-3) + hit->getGlobalZ()*cos(30.5e-3); + + + histos1d[m_name+"_gz"]->Fill(hit->getGlobalZ(),weight); + histos1d[m_name+"_rot1gz"]->Fill(rotz1,weight); + histos1d[m_name+"_rot2gz"]->Fill(rotz2,weight); + + //1D + + if (rotz2<50) { + + histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); + + + //2D + + + histos2d[m_name+"_charge_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + histos2d[m_name+"_charge_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); + } + +} + + + diff --git a/analysis/src/HistoManager.cxx b/analysis/src/HistoManager.cxx new file mode 100644 index 000000000..bb6278cd8 --- /dev/null +++ b/analysis/src/HistoManager.cxx @@ -0,0 +1,206 @@ +#include "HistoManager.h" +#include +#include "TKey.h" +#include "TClass.h" + + + + +void HistoManager::GetHistosFromFile(TFile* inFile, const std::string& name, const std::string& folder) { + + //Todo: use name as regular expression. + //Todo: use folder to choose a folder. + TIter next(inFile->GetListOfKeys()); + TKey *key; + while ((key = (TKey*)next())) { + std::string classType = key->GetClassName(); + if (classType.find("TH1")!=std::string::npos) + histos1d[key->GetName()] = (TH1F*) key->ReadObj(); + if (classType.find("TH2")!=std::string::npos) + histos2d[key->GetName()] = (TH2F*) key->ReadObj(); + if (classType.find("TH3")!=std::string::npos) + histos3d[key->GetName()] = (TH3F*) key->ReadObj(); + } +} + + + +TH1F* HistoManager::plot1D(const std::string& name,const std::string& xtitle, int nbinsX, float xmin, float xmax) { + TH1F* h= new TH1F(name.c_str(),name.c_str(),nbinsX,xmin,xmax); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->Sumw2(); + return h; +} + +TH1F* HistoManager::plot1D(const std::string& name,const std::string& xtitle, int nbinsX, double* axisX) { + TH1F* h= new TH1F(name.c_str(),name.c_str(),nbinsX,axisX); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->Sumw2(); + return h; +} + +TH2F* HistoManager::plot2D(std::string name, + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax) { + + TH2F* h = new TH2F(name.c_str(),name.c_str(), + nbinsX,xmin,xmax, + nbinsY,ymin,ymax); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; +} + +TH2F* HistoManager::plot2D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY) { + + TH2F * h = new TH2F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,axisY); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; +} + +TH2F* HistoManager::plot2D(std::string name, + std::string xtitle, int nbinsX, const double* axisX, + std::string ytitle, int nbinsY, const double* axisY) { + + TH2F * h = new TH2F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,axisY); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; +} + + + +TH2F* HistoManager::plot2D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, float ymin, float ymax) { + + TH2F * h = new TH2F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,ymin,ymax); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; +} + + +TH3F* HistoManager::plot3D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY, + std::string ztitle, int nbinsZ, double* axisZ) { + + + TH3F* h = new TH3F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,axisY, + nbinsZ,axisZ); + + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->GetZaxis()->SetTitle(ztitle.c_str()); + h->Sumw2(); + return h; +} + + + + +TH3F* HistoManager::plot3D(std::string name, + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax, + std::string ztitle, int nbinsZ, float zmin, float zmax) { + + + TH3F* h = new TH3F(name.c_str(),name.c_str(), + nbinsX,xmin,xmax, + nbinsY,ymin,ymax, + nbinsZ,zmin,zmax); + + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->GetZaxis()->SetTitle(ztitle.c_str()); + h->Sumw2(); + return h; +} + + + +void HistoManager::sumw2() { + + for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { + if (!it->second){ + std::cout<first<<" Null ptr in saving.."<second->Sumw2(); + } + + for (it2d it = histos2d.begin(); it!=histos2d.end(); ++it) { + if (!(it->second)) { + std::cout<first<<" Null ptr in saving.."<second->Sumw2(); + } + + for (it1d it = histos1d.begin(); it!=histos1d.end(); ++it) { + if (!it->second){ + std::cout<first<<" Null ptr in saving.."<second->Sumw2(); + } + +} + + + +void HistoManager::saveHistos(TFile* outF,std::string folder) { + + outF->cd(); + TDirectoryFile* dir = 0; + + if (!folder.empty()) { + dir = new TDirectoryFile(folder.c_str(),folder.c_str()); + dir->cd(); + } + + for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { + if (!it->second){ + std::cout<first<<" Null ptr in saving.."<second->Write(); + } + + for (it2d it = histos2d.begin(); it!=histos2d.end(); ++it) { + if (!(it->second)) { + std::cout<first<<" Null ptr in saving.."<second->Write(); + } + + for (it1d it = histos1d.begin(); it!=histos1d.end(); ++it) { + if (!it->second){ + std::cout<first<<" Null ptr in saving.."<second->Write(); + } + + if (dir) {delete dir; dir=0;} + +} + + diff --git a/analysis/src/runAnalysis.cxx b/analysis/src/runAnalysis.cxx new file mode 100644 index 000000000..e3fe7a7b7 --- /dev/null +++ b/analysis/src/runAnalysis.cxx @@ -0,0 +1,42 @@ + +#include "EventHeader.h" //CONTAINS LCIO. I don't want that! +#include "Track.h" +#include "TFile.h" +#include "TTree.h" + +#include "TBranch.h" + +#include + +int main(int argc, char** argv) { + + + TFile* inputFile = new TFile("/Users/Pierfrancesco/HPS/sw/hipster/run/testRun.root"); + TTree* t = (TTree*) inputFile->Get("HPS_Event"); + long nentries = t->GetEntriesFast(); + std::cout<<"n entries "<SetBranchAddress("GBLTracks",&tracks,&btracks); + + for (int ientry=0; ientry<100;ientry++) { + t->GetEntry(ientry); + std::cout<<"Number of Tracks in the event:"<GetEntries()<GetEntries();itrack++) { + Track *track = (Track*)tracks->ConstructedAt(itrack); + + std::cout<<"Tracks number of hits for track "<getNSvtHits()<cd();} + void close(); + + + private: + + HpsEvent* event_{nullptr}; + int entry_{0}; + int maxEntries_{0}; + TFile* ofile_{nullptr}; + TFile* rootfile_{nullptr}; + TTree* intree_{nullptr}; + + + //TTreeReader* ttree_reader; + +}; + + +#endif diff --git a/processing/include/IEventFile.h b/processing/include/IEventFile.h new file mode 100644 index 000000000..a3b58f454 --- /dev/null +++ b/processing/include/IEventFile.h @@ -0,0 +1,18 @@ +#ifndef __IEVENT_FILE_H__ +#define __IEVENT_FILE_H__ + +#include "IEvent.h" + +class IEventFile { + + public: + + virtual ~IEventFile(){}; + virtual bool nextEvent()=0; + virtual void setupEvent(IEvent* ievent)=0; + virtual void close()=0; + virtual void resetOutputFileDir() = 0; + +}; + +#endif diff --git a/processing/include/Process.h b/processing/include/Process.h index 5bd7d77c8..1ef58067a 100644 --- a/processing/include/Process.h +++ b/processing/include/Process.h @@ -66,6 +66,10 @@ class Process { /** Run the process. */ void run(); + /** Run the process on root files. */ + //TODO Write this better + void runOnRoot(); + /** Request that the processing finish with this event. */ void requestFinish() { event_limit_=0; } diff --git a/processing/include/Processor.h b/processing/include/Processor.h index 9ea9814ee..2219c7c2b 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -15,13 +15,13 @@ //-----------// // hpstr // //-----------// -#include "Event.h" #include "ParameterSet.h" // Forward declarations class Process; class Processor; -class TTree; +class TTree; +class IEvent; /** Typedef for ProcessorFactory use. */ typedef Processor* ProcessorMaker(const std::string& name, Process& process); @@ -70,7 +70,7 @@ class Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(Event* event) = 0; + virtual void process(IEvent* ievent) = 0; /** * Callback for the Processor to take any necessary diff --git a/processing/src/EventFile.cxx b/processing/src/EventFile.cxx index 106ff3c89..6da43320b 100644 --- a/processing/src/EventFile.cxx +++ b/processing/src/EventFile.cxx @@ -35,8 +35,8 @@ bool EventFile::nextEvent() { return true; } -void EventFile::setupEvent(Event* event) { - event_ = event; +void EventFile::setupEvent(IEvent* ievent) { + event_ = static_cast (ievent); entry_ = 0; } diff --git a/processing/src/HpsEventFile.cxx b/processing/src/HpsEventFile.cxx new file mode 100644 index 000000000..741d75a7c --- /dev/null +++ b/processing/src/HpsEventFile.cxx @@ -0,0 +1,41 @@ +#include "HpsEventFile.h" + +HpsEventFile::HpsEventFile(const std::string ifilename, const std::string& ofilename){ + rootfile_ = new TFile(ifilename.c_str()); + //ttree_reader = new ("HPS_Event",_rootfile); + intree_ = (TTree*)rootfile_->Get("HPS_Event"); + ofile_ = new TFile(ofilename.c_str(),"recreate"); + +} + +HpsEventFile::~HpsEventFile() {} + +void HpsEventFile::setupEvent(IEvent* ievent) { + event_ = static_cast(ievent); + //TODO protect the tree pointer + if (intree_) { + event_ -> setTree(intree_); + maxEntries_ = intree_->GetEntriesFast(); + } + + entry_ = 0; +} + +void HpsEventFile::close() { + + ofile_->cd(); + ofile_->Close(); + +} + +bool HpsEventFile::nextEvent() { + + ++entry_; + if (entry_>maxEntries_) + return false; + + //TODO Really don't like having the tree associated to the event object. Should be associated to the EventFile. + intree_->GetEntry(entry_); + + return true; +} diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 87aee80f8..3ba3aaebd 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -6,9 +6,58 @@ #include "Process.h" #include "EventFile.h" +#include "HpsEventFile.h" Process::Process() {} +//TODO Fix this better + +void Process::runOnRoot() { + try { + int n_events_processed = 0; + HpsEvent event; + int cfile =0 ; + for (auto ifile : input_files_) { + std::cout<<"Processing file"<setupEvent(&event); + } + for (auto module : sequence_) { + module->initialize(event.getTree()); + } + while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { + if (n_events_processed%100 == 0) + std::cout<<"Event:"<process(&event); + //if (!module->process(&event)) + //break; + } + //event.Clear(); + ++n_events_processed; + } + //Pass to next file + ++cfile; + // Finalize all modules + for (auto module : sequence_) { + std::cout<<"Finalize your processors here"<close(); + delete file; + file = nullptr; + } + } + } catch (std::exception& e) { + std::cerr<<"Error:"<run(); + + //TODO Make this better + if (processRoot) + p->runOnRoot(); + else + p->run(); std::cout << "---- [ hpstr ]: Event processing complete --------" << std::endl; diff --git a/processors/CMakeLists.txt b/processors/CMakeLists.txt index a4f264357..96c41806d 100644 --- a/processors/CMakeLists.txt +++ b/processors/CMakeLists.txt @@ -2,6 +2,6 @@ # Declare processors module module( NAME processors - DEPENDENCIES event processing + DEPENDENCIES event processing analysis EXTERNAL_DEPENDENCIES ROOT LCIO ) diff --git a/processors/include/ClusterOnTrackProcessor.h b/processors/include/ClusterOnTrackProcessor.h new file mode 100644 index 000000000..1d9cfcaa6 --- /dev/null +++ b/processors/include/ClusterOnTrackProcessor.h @@ -0,0 +1,44 @@ +#ifndef __CLUSTERONTRACK_PROCESSOR_H__ +#define __CLUSTERONTRACK_PROCESSOR_H__ + +//HPSTR +#include "HpsEvent.h" +#include "Track.h" + + +//ROOT +#include "ClusterHistos.h" +#include "Processor.h" +#include "TClonesArray.h" + +class TTree; + + +class ClusterOnTrackProcessor : public Processor { + + public: + + ClusterOnTrackProcessor(const std::string& name, Process& process); + + ~ClusterOnTrackProcessor(); + + virtual void process(IEvent* ievent); + + virtual void initialize(TTree* tree); + + virtual void finalize(); + + private: + + ClusterHistos* clusterHistos; + //TODO Change this to be held from HPSEvent + TTree* tree_; + TClonesArray* tracks_{nullptr}; + TBranch* btracks_{nullptr}; + TClonesArray* hits_{nullptr}; + TBranch* bhits_{nullptr}; + +}; + + +#endif diff --git a/processors/include/ECalDataProcessor.h b/processors/include/ECalDataProcessor.h index 98f130e66..dc6b0e61c 100644 --- a/processors/include/ECalDataProcessor.h +++ b/processors/include/ECalDataProcessor.h @@ -59,7 +59,7 @@ class ECalDataProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(Event* event); + virtual void process(IEvent* event); /** * Callback for the Processor to take any necessary diff --git a/processors/include/EventProcessor.h b/processors/include/EventProcessor.h index 1e3f18aa4..161155d8d 100644 --- a/processors/include/EventProcessor.h +++ b/processors/include/EventProcessor.h @@ -31,6 +31,7 @@ #include "EventHeader.h" #include "Processor.h" #include "TriggerData.h" +#include "Event.h" // Forward declarations class TTree; @@ -55,7 +56,7 @@ class EventProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(Event* event); + virtual void process(IEvent* ievent); /** * Callback for the Processor to take any necessary diff --git a/processors/include/HPSEventProcessor.h b/processors/include/HPSEventProcessor.h new file mode 100644 index 000000000..fb999f0d9 --- /dev/null +++ b/processors/include/HPSEventProcessor.h @@ -0,0 +1,28 @@ +#ifndef _HPSEVENT_HEADER_PROCESSOR_H__ +#define _HPSEVENT_HEADER_PROCESSOR_H__ + +#include "TClonesArray.h" + +#include "Processor.h" +#include "HpsEvent.h" +#include "TTree.h" + + + +class HPSEventProcessor : public Processor { + + public: + + HPSEventProcessor(const std::string& name, Process& process); + ~HPSEventProcessor(); + + virtual void process(IEvent* ievent); + virtual void initialize(TTree* tree); + virtual void finalize(); + + private: + TClonesArray* header_{nullptr}; + +}; + +#endif diff --git a/processors/include/ParticleProcessor.h b/processors/include/ParticleProcessor.h index 5fa0991a3..cc9bce9d5 100644 --- a/processors/include/ParticleProcessor.h +++ b/processors/include/ParticleProcessor.h @@ -37,6 +37,7 @@ #include "Particle.h" #include "Processor.h" #include "Track.h" +#include "Event.h" // Forward declarations class TTree; @@ -73,7 +74,7 @@ class ParticleProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(Event* event); + virtual void process(IEvent* ievent); /** * Callback for the Processor to take any necessary diff --git a/processors/include/SvtDataProcessor.h b/processors/include/SvtDataProcessor.h index c0d80d177..9bc4542a0 100644 --- a/processors/include/SvtDataProcessor.h +++ b/processors/include/SvtDataProcessor.h @@ -34,6 +34,7 @@ #include "Processor.h" #include "Track.h" #include "TrackerHit.h" +#include "Event.h" // Forward declarations class TTree; @@ -58,7 +59,7 @@ class SvtDataProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(Event* event); + virtual void process(IEvent* ievent); /** * Callback for the Processor to take any necessary diff --git a/processors/include/SvtRawDataProcessor.h b/processors/include/SvtRawDataProcessor.h index a27b075cc..3ce96d428 100644 --- a/processors/include/SvtRawDataProcessor.h +++ b/processors/include/SvtRawDataProcessor.h @@ -33,6 +33,7 @@ #include "Collections.h" #include "Processor.h" #include "RawSvtHit.h" +#include "Event.h" class TTree; @@ -56,7 +57,7 @@ class SvtRawDataProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(Event* event); + virtual void process(IEvent* ievent); /** * Callback for the Processor to take any necessary diff --git a/processors/src/ClusterOnTrackProcessor.cxx b/processors/src/ClusterOnTrackProcessor.cxx new file mode 100644 index 000000000..1d9c0babf --- /dev/null +++ b/processors/src/ClusterOnTrackProcessor.cxx @@ -0,0 +1,33 @@ +#include "ClusterOnTrackProcessor.h" +#include "TBranch.h" + +ClusterOnTrackProcessor::ClusterOnTrackProcessor(const std::string& name, Process& process) : Processor(name,process){} +//TODO CHECK THIS DESTRUCTOR +ClusterOnTrackProcessor::~ClusterOnTrackProcessor(){} + +void ClusterOnTrackProcessor::initialize(TTree* tree) { + clusterHistos = new ClusterHistos("default_"); + tree_=tree; + //TODO Change this. + tree_->SetBranchAddress("GBLTracks",&tracks_,&btracks_); + +} + +void ClusterOnTrackProcessor::process(IEvent* ievent) { + + + for (int itrack = 0; itrackGetEntries();itrack++) { + Track *track = (Track*)tracks_->ConstructedAt(itrack); + + std::cout<<"Tracks number of hits for track "<getNSvtHits()< (ievent); EVENT::LCCollection* hits{nullptr}; std::string hits_coll_name = Collections::ECAL_TIME_CORR_HITS; try { diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index bfe395c0d..1a413bc10 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -6,6 +6,7 @@ #include "EventProcessor.h" + EventProcessor::EventProcessor(const std::string& name, Process& process) : Processor(name, process) { } @@ -16,8 +17,9 @@ EventProcessor::~EventProcessor() { void EventProcessor::initialize(TTree* tree) { } -void EventProcessor::process(Event* event) { - +void EventProcessor::process(IEvent* ievent) { + + Event* event = static_cast (ievent); /*EventHeader* header = static_cast(header_->ConstructedAt(0));*/ EventHeader& header = event->getEventHeaderMutable(); diff --git a/processors/src/HPSEventProcessor.cxx b/processors/src/HPSEventProcessor.cxx new file mode 100644 index 000000000..197a50ea0 --- /dev/null +++ b/processors/src/HPSEventProcessor.cxx @@ -0,0 +1,26 @@ +#include "HPSEventProcessor.h" +#include + +HPSEventProcessor::HPSEventProcessor(const std::string& name, Process& process) + : Processor(name,process) { +} + +HPSEventProcessor::~HPSEventProcessor(){ +} + +void HPSEventProcessor::initialize(TTree*) { +} + +void HPSEventProcessor::process(IEvent* ievent) { + HpsEvent* event = static_cast(ievent); + + std::cout<<"This is the HPSEventProcessor"< (ievent); for (auto& collections : collections_) { // Get the collection from the event diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx index 4d17faf11..9d93dd7fb 100644 --- a/processors/src/SvtDataProcessor.cxx +++ b/processors/src/SvtDataProcessor.cxx @@ -14,9 +14,10 @@ void SvtDataProcessor::initialize(TTree* tree) { hits_ = new TClonesArray("TrackerHit", 100000); } -void SvtDataProcessor::process(Event* event) { +void SvtDataProcessor::process(IEvent* ievent) { + Event* event = static_cast (ievent); // Get the collection of 3D hits from the LCIO event. If no such collection // exist, a DataNotAvailableException is thrown EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::TRACKER_HITS); diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index b0fc8e790..27fd6ffff 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -17,7 +17,9 @@ void SvtRawDataProcessor::initialize(TTree* tree) { rawhits_ = new TClonesArray("RawSvtHit", 100000); } -void SvtRawDataProcessor::process(Event* event) { +void SvtRawDataProcessor::process(IEvent* ievent) { + + Event* event = static_cast(ievent); UTIL::LCRelationNavigator* rawTracker_hit_fits_nav; EVENT::LCCollection* raw_svt_hit_fits; // Get the collection of 3D hits from the LCIO event. If no such collection From 1e9ec51708c0175a3614302ff347a92192411b51 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Wed, 4 Sep 2019 16:29:57 -0700 Subject: [PATCH 093/314] Fix on lambda and phi kinks array size --- event/include/Track.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/event/include/Track.h b/event/include/Track.h index 3f4f53c49..e6344b8a3 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -284,10 +284,10 @@ class Track : public TObject { double z_at_ecal_{-999}; /** Array used to store the lambda kinks for each of the sensor layers. */ - double lambda_kinks_[12]; + double lambda_kinks_[14]; /** Array used to store the phi kinks for each of the sensor layers. */ - double phi_kinks_[12]; + double phi_kinks_[14]; /** Track momentum. */ double px_{-9999}; From da2eed0991ee28d9d8f08d070c9465d2ed475bac Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 5 Sep 2019 14:51:15 -0700 Subject: [PATCH 094/314] Changed Processor::process to return bool (allows for event processing check). Support for stl containers in root files. Updates to cluster histos. Automatic rotation of TrackerHits coordinates to SVT ref frame. More comprehensive return of RawHit fit values --- analysis/include/ClusterHistos.h | 12 +- analysis/src/ClusterHistos.cxx | 153 +++++++--- event/include/Event.h | 10 +- event/include/EventLinkDef.h | 9 + event/include/RawSvtHit.h | 15 + event/include/TrackerHit.h | 33 ++- event/src/TrackerHit.cxx | 14 +- processing/include/Processor.h | 3 +- processing/src/Process.cxx | 5 +- processors/include/ClusterOnTrackProcessor.h | 11 +- processors/include/ECalDataProcessor.h | 2 +- processors/include/EventProcessor.h | 3 +- processors/include/HPSEventProcessor.h | 2 +- processors/include/ParticleProcessor.h | 2 +- processors/include/SvtDataProcessor.h | 2 +- processors/include/SvtRawDataProcessor.h | 2 +- processors/include/TrackingProcessor.h | 97 +++++++ processors/src/ClusterOnTrackProcessor.cxx | 31 +- processors/src/ECalDataProcessor.cxx | 3 +- processors/src/EventProcessor.cxx | 10 +- processors/src/HPSEventProcessor.cxx | 3 +- processors/src/ParticleProcessor.cxx | 5 +- processors/src/SvtDataProcessor.cxx | 4 +- processors/src/SvtRawDataProcessor.cxx | 12 +- processors/src/TrackingProcessor.cxx | 280 +++++++++++++++++++ 25 files changed, 636 insertions(+), 87 deletions(-) create mode 100644 processors/include/TrackingProcessor.h create mode 100644 processors/src/TrackingProcessor.cxx diff --git a/analysis/include/ClusterHistos.h b/analysis/include/ClusterHistos.h index 597347754..91a6c7555 100644 --- a/analysis/include/ClusterHistos.h +++ b/analysis/include/ClusterHistos.h @@ -5,6 +5,7 @@ #include "HistoManager.h" #include "TrackerHit.h" +#include "RawSvtHit.h" #include @@ -29,7 +30,16 @@ class ClusterHistos : public HistoManager{ private: - + std::vector layers{"ly0","ly1","ly2","ly3","ly4","ly5","ly6"}; + std::vector volumes{"top","bottom"}; + std::vector sides{"axial","stereo"}; + std::vector variables{"charge","cluSize"}; + + std::map cluSizeMap; + std::map chargeMap; + std::map cluPositionMap; + + }; diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx index 9bc5aabfa..329977a8b 100644 --- a/analysis/src/ClusterHistos.cxx +++ b/analysis/src/ClusterHistos.cxx @@ -5,66 +5,137 @@ void ClusterHistos::Define1DHistos() { //TODO improve this naming scheme std::string h_name = ""; - - //Cluster position - histos1d[m_name+"_gz"] = plot1D(m_name+"_gz", - "Global Z [mm]",20000,-1000,2000); - - histos1d[m_name+"_rot1gz"] = plot1D(m_name+"_rot1gz", - "Global Z [mm]",20000,-1000,2000); - - histos1d[m_name+"_rot2gz"] = plot1D(m_name+"_rot2gz", - "Global Z [mm]",20000,-1000,2000); - - + //Cluster position + histos1d[m_name+"_gz"] = plot1D(m_name+"_gz","Global Z [mm]",20000,-1000,2000); - histos1d[m_name+"_charge"] = plot1D(m_name+"_edep", - "edep",30,0,3e-5); + //2D hits plots + for (unsigned int iv = 0 ; iv < volumes.size(); ++iv) { + for (unsigned int ily = 0; ily < layers.size(); ++ily) { + for (unsigned int is = 0; is < sides.size(); ++is) { + + h_name = m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_charge"; + histos1d[h_name] = plot1D(h_name,"charge",100,0,10000); + + h_name = m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_cluSize"; + histos1d[h_name] = plot1D(h_name,"cluSize",10,0,10); + cluSizeMap[h_name] = 0; + chargeMap[h_name] = 0.; + cluPositionMap[h_name] = 0.; + } + } + } } - void ClusterHistos::Define2DHistos() { std::string h_name = ""; - histos2d[m_name+"_charge_vs_gx"] = plot2D(m_name+"_charge_vs_gx", "Global X [mm] ",100,0,100, - "edep",30,0,3e-5); - + "edep",100,0,10000); int nbins = 1000; float pitch = 0.055; histos2d[m_name+"_charge_vs_gy"] = plot2D(m_name+"_charge_vs_gy", "Gloabl Y [mm]",nbins,0.750,(nbins+1)*0.055, - "edep",30,0,3e-5); + "edep",100,0,10000); + + for (unsigned int iv = 0 ; iv < volumes.size(); ++iv) { + for (unsigned int ily = 0; ily < layers.size(); ++ily) { + for (unsigned int is = 0; is < sides.size(); ++is) { + + h_name = m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_charge_vs_stripPos"; + histos2d[h_name] = plot2D(h_name, + "Strip Position",640,0,640, + "charge",100,0,10000); + + h_name = m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_charge_vs_globRad"; + histos2d[h_name] = plot2D(h_name, + "#sqrt{x^{2} + y^{2}}",600,0,150, + "charge",100,0,10000); + } + } + } } void ClusterHistos::FillHistograms(TrackerHit* hit,float weight) { + TRefArray* rawhits_ = hit->getRawHits(); + int iv = -1; // 0 top, 1 bottom + int is = -1; // 0 axial, 1 stereo + int ily = -1; // 0-6 + + //TODO do this better + //std::cout<<"Size:" <GetEntries()<GetEntries(); ++irh) { + + RawSvtHit * rawhit = static_cast(rawhits_->At(irh)); + //rawhit layers go from 1 to 14. Example: RawHit->Layer1 is layer0 axial on top and layer0 stereo in bottom. + ily = (rawhit->getLayer() - 1) / 2; + + //Get the volume: even = top, odd = bottom + if (rawhit->getModule() % 2 == 0) + iv = 0; + else + iv = 1; + //top volume + if (!iv) { + //layer odd => axial / layer even => stereo + if (rawhit->getLayer() % 2 != 0) + is = 0; + else + is = 1; + } + //bottom volume + else { + //layer even => axial / layer odd => stereo + if (rawhit->getLayer() % 2 == 0) + is = 0; + else + is = 1; + } + //std::cout<<"ily:"<Fill(1e-5,weight); - float rotz1 = -hit->getGlobalX() * sin(30.5e-3) + hit->getGlobalZ()*cos(30.5e-3); - float rotz2 = hit->getGlobalX() * sin(30.5e-3) + hit->getGlobalZ()*cos(30.5e-3); - + //2D cluster charge + chargeMap [m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_charge"] += rawhit->getAmp(); + //2D cluster size + cluSizeMap [m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_cluSize"] ++; + + //2D Weighted position numerator + cluPositionMap[m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_charge"] += rawhit->getAmp()*rawhit->getStrip(); + //std::cout<<"rawhit->getStrip()::"<getStrip()<::iterator it = cluSizeMap.begin(); it!=cluSizeMap.end(); ++it ) { + if (it->second != 0) { + //std::cout<<"Filling..."<first<<" "<first]<first]->Fill(it->second,weight); + cluSizeMap[it->first]= 0; + } + } + for (std::map::iterator it = chargeMap.begin(); it!=chargeMap.end(); ++it ) { + //Avoid comparing to 0.0 + if (it->second > 1e-6) { + //std::cout<<"Filling..."<first<<" "<first]<second holds the charge + //it->first = charge histogram name. + double charge = it->second; + histos1d[it->first]->Fill(charge,weight); + double weighted_pos = cluPositionMap[it->first] / (charge); + //std::cout<<"weighted pos "<first+"_vs_stripPos"]->Fill(weighted_pos,charge,weight); + double globRad = sqrt(hit->getGlobalX() * hit->getGlobalX() + hit->getGlobalY()+hit->getGlobalY()); + histos2d[it->first+"_vs_globRad"]->Fill(globRad,charge,weight); + chargeMap[it->first] = 0.0; + cluPositionMap[it->first] = 0.0; + } + } histos1d[m_name+"_gz"]->Fill(hit->getGlobalZ(),weight); - histos1d[m_name+"_rot1gz"]->Fill(rotz1,weight); - histos1d[m_name+"_rot2gz"]->Fill(rotz2,weight); - //1D - - if (rotz2<50) { - - histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); - - - //2D - - - histos2d[m_name+"_charge_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); - histos2d[m_name+"_charge_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); - } - + //histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); + //2D + //histos2d[m_name+"_charge_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + //histos2d[m_name+"_charge_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); } - - - diff --git a/event/include/Event.h b/event/include/Event.h index 6da875fb8..724854c4c 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -12,6 +12,7 @@ // C++ StdLib // //----------------// #include +#include //----------// // LCIO // @@ -55,6 +56,13 @@ class Event : public IEvent { */ void addCollection(const std::string name, TClonesArray* collection); + /** TODO fix docu + * Add a collection (std::vector) of objects to the event. */ + + template + void addCollection(const std::string& name, std::vector* collection ){ + branches_[name] = tree_->Branch(name.c_str(),&collection);}; + /** * @param name Name of the collection * @@ -112,7 +120,7 @@ class Event : public IEvent { EVENT::LCEvent* lc_event_{nullptr}; /** Container with all TClonesArray collections. */ - std::map objects_; + std::map objects_; /** Container will all branches. */ std::map branches_; diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 6cffb6b84..35b9a7dcc 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -14,4 +14,13 @@ #pragma link C++ class TrackerHit+; #pragma link C++ class RawSvtHit+; +// This is to create the dictionary for stl containers +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #endif diff --git a/event/include/RawSvtHit.h b/event/include/RawSvtHit.h index 6293af650..439fde131 100644 --- a/event/include/RawSvtHit.h +++ b/event/include/RawSvtHit.h @@ -85,6 +85,21 @@ class RawSvtHit : public TObject { /** Get the strip */ int getStrip(); + /** Get the t0 fit parameter */ + double getT0() {return fit_[0];} + + /** Get the t0 err fit parameter */ + double getT0err() {return fit_[1];} + + /** Get the amplitude fit parameter */ + double getAmp() {return fit_[2];} + + /** Get the amplitude error fit parameter */ + double getAmpErr() {return fit_[3];} + + /** Get the chiSq probability */ + double getChiSq() {return fit_[4];} + ClassDef(RawSvtHit, 1); private: diff --git a/event/include/TrackerHit.h b/event/include/TrackerHit.h index 5ce806ae9..c4907732e 100644 --- a/event/include/TrackerHit.h +++ b/event/include/TrackerHit.h @@ -17,6 +17,7 @@ //----------// #include #include +#include class TrackerHit : public TObject { @@ -30,21 +31,29 @@ class TrackerHit : public TObject { /** Reset the Hit object. */ void Clear(Option_t *option=""); + + /** Get the references to the raw hits associated with this tracker hit */ + TRefArray* getRawHits() const {return raw_hits_;}; /** * Set the hit position. * * @param position The hit position. */ - void setPosition(const double* position); + void setPosition(const double* position, bool rotate = false); - //TODO: stupid to return a vector. + //TODO: avoid returning a vector, rather pass by ref. /** @return The hit position. */ std::vector getPosition() const { return {x_, y_, z_}; }; - double getGlobalX() const {return x_;} - double getGlobalY() const {return y_;} - double getGlobalZ() const {return z_;} + /** @return the global X coordinate of the hit */ + double getGlobalX() const {return x_;} + + /** @return the global X coordinate of the hit */ + double getGlobalY() const {return y_;} + + /** @return the global X coordinate of the hit */ + double getGlobalZ() const {return z_;} /** * Set the covariance matrix. @@ -73,14 +82,23 @@ class TrackerHit : public TObject { */ void setCharge(const double charge) { charge_ = charge; }; - /** @return The hit time. */ double getCharge() const { return charge_; }; + + /** Add raw hit to the raw hit reference array */ + void addRawHit(TObject* rawhit) { + ++n_rawhits_; + raw_hits_->Add(rawhit); + } + ClassDef(TrackerHit, 1); private: + /** Number of raw hits forming the Tracker hit */ + int n_rawhits_{0}; + /** The x position of the hit. */ double x_{-999}; @@ -103,6 +121,9 @@ class TrackerHit : public TObject { /** The hit charge deposit. */ double charge_{-999}; + + /** The raw hits */ + TRefArray* raw_hits_{new TRefArray{}}; }; // TrackerHit diff --git a/event/src/TrackerHit.cxx b/event/src/TrackerHit.cxx index 7176662c5..a96b0e8d6 100644 --- a/event/src/TrackerHit.cxx +++ b/event/src/TrackerHit.cxx @@ -20,10 +20,20 @@ void TrackerHit::Clear(Option_t* /* options */) { TObject::Clear(); } -void TrackerHit::setPosition(const double* position) { +void TrackerHit::setPosition(const double* position, bool rotate) { + + //Rotate the the input position automatically to match with the SVT tracker system + if (rotate) + { + x_ = position[1]; + y_ = position[2]; + z_ = position[1] * sin(30.5e-3) + position[0]*cos(30.5e-3); + } + else { x_ = position[0]; y_ = position[1]; - z_ = position[2]; + z_ = position[2]; + } } void TrackerHit::setCovarianceMatrix(const std::vector covariance_matrix) { diff --git a/processing/include/Processor.h b/processing/include/Processor.h index 2219c7c2b..49655f153 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -69,8 +69,9 @@ class Processor { /** * Process the event and put new data products into it. * @param event The Event to process. + * @return status of the processing, false will move to next event and skip other processes. */ - virtual void process(IEvent* ievent) = 0; + virtual bool process(IEvent* ievent) = 0; /** * Callback for the Processor to take any necessary diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 3ba3aaebd..ec17582ec 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -28,7 +28,7 @@ void Process::runOnRoot() { module->initialize(event.getTree()); } while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { - if (n_events_processed%100 == 0) + if (n_events_processed%1000 == 0) std::cout<<"Event:"<finalize(); } // TODO Check all these destructors if (file) { diff --git a/processors/include/ClusterOnTrackProcessor.h b/processors/include/ClusterOnTrackProcessor.h index 1d9cfcaa6..73ddf991d 100644 --- a/processors/include/ClusterOnTrackProcessor.h +++ b/processors/include/ClusterOnTrackProcessor.h @@ -4,12 +4,14 @@ //HPSTR #include "HpsEvent.h" #include "Track.h" +#include "TrackerHit.h" //ROOT #include "ClusterHistos.h" #include "Processor.h" #include "TClonesArray.h" +#include "TFile.h" class TTree; @@ -22,7 +24,7 @@ class ClusterOnTrackProcessor : public Processor { ~ClusterOnTrackProcessor(); - virtual void process(IEvent* ievent); + virtual bool process(IEvent* ievent); virtual void initialize(TTree* tree); @@ -33,10 +35,11 @@ class ClusterOnTrackProcessor : public Processor { ClusterHistos* clusterHistos; //TODO Change this to be held from HPSEvent TTree* tree_; - TClonesArray* tracks_{nullptr}; + std::vector *tracks_{}; TBranch* btracks_{nullptr}; - TClonesArray* hits_{nullptr}; - TBranch* bhits_{nullptr}; + std::vector hits_{}; + TBranch* bhits_{nullptr}; + TFile* outF_{nullptr}; }; diff --git a/processors/include/ECalDataProcessor.h b/processors/include/ECalDataProcessor.h index dc6b0e61c..81bf5b4f9 100644 --- a/processors/include/ECalDataProcessor.h +++ b/processors/include/ECalDataProcessor.h @@ -59,7 +59,7 @@ class ECalDataProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(IEvent* event); + virtual bool process(IEvent* event); /** * Callback for the Processor to take any necessary diff --git a/processors/include/EventProcessor.h b/processors/include/EventProcessor.h index 161155d8d..631c6dda0 100644 --- a/processors/include/EventProcessor.h +++ b/processors/include/EventProcessor.h @@ -56,7 +56,7 @@ class EventProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(IEvent* ievent); + virtual bool process(IEvent* ievent); /** * Callback for the Processor to take any necessary @@ -73,6 +73,7 @@ class EventProcessor : public Processor { private: TClonesArray* header_{nullptr}; + bool _debug{false}; }; // EventProcessor diff --git a/processors/include/HPSEventProcessor.h b/processors/include/HPSEventProcessor.h index fb999f0d9..79fab8d53 100644 --- a/processors/include/HPSEventProcessor.h +++ b/processors/include/HPSEventProcessor.h @@ -16,7 +16,7 @@ class HPSEventProcessor : public Processor { HPSEventProcessor(const std::string& name, Process& process); ~HPSEventProcessor(); - virtual void process(IEvent* ievent); + virtual bool process(IEvent* ievent); virtual void initialize(TTree* tree); virtual void finalize(); diff --git a/processors/include/ParticleProcessor.h b/processors/include/ParticleProcessor.h index cc9bce9d5..845c566ba 100644 --- a/processors/include/ParticleProcessor.h +++ b/processors/include/ParticleProcessor.h @@ -74,7 +74,7 @@ class ParticleProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(IEvent* ievent); + virtual bool process(IEvent* ievent); /** * Callback for the Processor to take any necessary diff --git a/processors/include/SvtDataProcessor.h b/processors/include/SvtDataProcessor.h index 9bc4542a0..6d90b0c74 100644 --- a/processors/include/SvtDataProcessor.h +++ b/processors/include/SvtDataProcessor.h @@ -59,7 +59,7 @@ class SvtDataProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(IEvent* ievent); + virtual bool process(IEvent* ievent); /** * Callback for the Processor to take any necessary diff --git a/processors/include/SvtRawDataProcessor.h b/processors/include/SvtRawDataProcessor.h index 3ce96d428..3c196b961 100644 --- a/processors/include/SvtRawDataProcessor.h +++ b/processors/include/SvtRawDataProcessor.h @@ -57,7 +57,7 @@ class SvtRawDataProcessor : public Processor { * Process the event and put new data products into it. * @param event The Event to process. */ - virtual void process(IEvent* ievent); + virtual bool process(IEvent* ievent); /** * Callback for the Processor to take any necessary diff --git a/processors/include/TrackingProcessor.h b/processors/include/TrackingProcessor.h new file mode 100644 index 000000000..5b5525ef3 --- /dev/null +++ b/processors/include/TrackingProcessor.h @@ -0,0 +1,97 @@ +/** + * + */ + +#ifndef __TRACKING_PROCESSOR_H__ +#define __TRACKING_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "Track.h" +#include "TrackerHit.h" +#include "Event.h" +#include "RawSvtHit.h" + +// Forward declarations +class TTree; + +class TrackingProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + TrackingProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~TrackingProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual bool process(IEvent* ievent); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(TTree* tree); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Container to hold all TrackerHit objects. */ + std::vector hits_{}; + + /** Container to hold all Track objects. */ + std::vector tracks_{}; + + /** Container to hold all raw hits objecs. */ + std::vector rawhits_{}; + bool _debug{false}; + + + + + +}; // Tracking Processor + +#endif // __TRACKING_PROCESSOR_H__ diff --git a/processors/src/ClusterOnTrackProcessor.cxx b/processors/src/ClusterOnTrackProcessor.cxx index 1d9c0babf..c3c0e1ad0 100644 --- a/processors/src/ClusterOnTrackProcessor.cxx +++ b/processors/src/ClusterOnTrackProcessor.cxx @@ -6,28 +6,35 @@ ClusterOnTrackProcessor::ClusterOnTrackProcessor(const std::string& name, Proces ClusterOnTrackProcessor::~ClusterOnTrackProcessor(){} void ClusterOnTrackProcessor::initialize(TTree* tree) { - clusterHistos = new ClusterHistos("default_"); - tree_=tree; + clusterHistos = new ClusterHistos("hitOnTrack_2D"); + clusterHistos->Define1DHistos(); + clusterHistos->Define2DHistos(); + tree_= tree; //TODO Change this. tree_->SetBranchAddress("GBLTracks",&tracks_,&btracks_); + //TODO Change this. + outF_ = new TFile("outputFile.root","recreate"); } -void ClusterOnTrackProcessor::process(IEvent* ievent) { - +bool ClusterOnTrackProcessor::process(IEvent* ievent) { - for (int itrack = 0; itrackGetEntries();itrack++) { - Track *track = (Track*)tracks_->ConstructedAt(itrack); - - std::cout<<"Tracks number of hits for track "<getNSvtHits()<size();itrack++) { + Track *track = tracks_->at(itrack); + //Loop on hits + for (int ihit = 0; ihitgetSvtHits()->GetEntries(); ++ihit) { + TrackerHit* hit3d = (TrackerHit*) track->getSvtHits()->At(ihit); + clusterHistos->FillHistograms(hit3d,1.); + } + } + return true; } - void ClusterOnTrackProcessor::finalize() { - -} + clusterHistos->saveHistos(outF_,""); + +} DECLARE_PROCESSOR(ClusterOnTrackProcessor); diff --git a/processors/src/ECalDataProcessor.cxx b/processors/src/ECalDataProcessor.cxx index 83da3bbb1..6cf8cd159 100644 --- a/processors/src/ECalDataProcessor.cxx +++ b/processors/src/ECalDataProcessor.cxx @@ -20,7 +20,7 @@ void ECalDataProcessor::initialize(TTree* tree) { clusters_ = new TClonesArray("CalCluster", 1000000); } -void ECalDataProcessor::process(IEvent* ievent) { +bool ECalDataProcessor::process(IEvent* ievent) { // Attempt to retrieve the collection "TimeCorrEcalHits" from the event. If // the collection doesn't exist, handle the DataNotAvailableCollection and @@ -139,6 +139,7 @@ void ECalDataProcessor::process(IEvent* ievent) { event->addCollection(Collections::ECAL_CLUSTERS, clusters_); + return true; } void ECalDataProcessor::finalize() { diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index 1a413bc10..2fff9cdb6 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -17,7 +17,7 @@ EventProcessor::~EventProcessor() { void EventProcessor::initialize(TTree* tree) { } -void EventProcessor::process(IEvent* ievent) { +bool EventProcessor::process(IEvent* ievent) { Event* event = static_cast (ievent); /*EventHeader* header @@ -26,6 +26,11 @@ void EventProcessor::process(IEvent* ievent) { EVENT::LCEvent* lc_event = event->getLCEvent(); + if (_debug) { + std::cout<<"Event Number: "<getEventNumber()<getRunNumber()<getEventNumber()); @@ -114,6 +119,9 @@ void EventProcessor::process(IEvent* ievent) { } event->add(Collections::EVENT_HEADERS, &header); + + return true; + } void EventProcessor::finalize() { diff --git a/processors/src/HPSEventProcessor.cxx b/processors/src/HPSEventProcessor.cxx index 197a50ea0..154031ebe 100644 --- a/processors/src/HPSEventProcessor.cxx +++ b/processors/src/HPSEventProcessor.cxx @@ -11,10 +11,11 @@ HPSEventProcessor::~HPSEventProcessor(){ void HPSEventProcessor::initialize(TTree*) { } -void HPSEventProcessor::process(IEvent* ievent) { +bool HPSEventProcessor::process(IEvent* ievent) { HpsEvent* event = static_cast(ievent); std::cout<<"This is the HPSEventProcessor"< (ievent); for (auto& collections : collections_) { @@ -182,8 +182,9 @@ void ParticleProcessor::process(IEvent* ievent) { } // Add the hit collection to the event - event->addCollection(collections.first, collections.second); + event->addCollection(collections.first, collections.second); } + return true; } void ParticleProcessor::finalize() { diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx index 9d93dd7fb..4f494773f 100644 --- a/processors/src/SvtDataProcessor.cxx +++ b/processors/src/SvtDataProcessor.cxx @@ -14,10 +14,11 @@ void SvtDataProcessor::initialize(TTree* tree) { hits_ = new TClonesArray("TrackerHit", 100000); } -void SvtDataProcessor::process(IEvent* ievent) { +bool SvtDataProcessor::process(IEvent* ievent) { Event* event = static_cast (ievent); + // Get the collection of 3D hits from the LCIO event. If no such collection // exist, a DataNotAvailableException is thrown EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::TRACKER_HITS); @@ -193,6 +194,7 @@ void SvtDataProcessor::process(IEvent* ievent) { event->addCollection(Collections::GBL_TRACKS, tracks_); + return true; } void SvtDataProcessor::finalize() { diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 27fd6ffff..29d60de4a 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -17,14 +17,15 @@ void SvtRawDataProcessor::initialize(TTree* tree) { rawhits_ = new TClonesArray("RawSvtHit", 100000); } -void SvtRawDataProcessor::process(IEvent* ievent) { +bool SvtRawDataProcessor::process(IEvent* ievent) { Event* event = static_cast(ievent); UTIL::LCRelationNavigator* rawTracker_hit_fits_nav; EVENT::LCCollection* raw_svt_hit_fits; // Get the collection of 3D hits from the LCIO event. If no such collection // exist, a DataNotAvailableException is thrown - EVENT::LCCollection* raw_svt_hits = event->getLCCollection(Collections::RAW_SVT_HITS); + EVENT::LCCollection* raw_svt_hits = event->getLCCollection(Collections::RAW_SVT_HITS); + //Check to see if fits are in the file auto evColls = event->getLCEvent()->getCollectionNames(); @@ -45,9 +46,9 @@ void SvtRawDataProcessor::process(IEvent* ievent) { // Loop over all of the raw SVT hits in the LCIO event and add them to the // HPS event - for (int ihit = 0; ihit < raw_svt_hits->getNumberOfElements(); ++ihit) { + for (int ihit = 0; ihit < raw_svt_hits->getNumberOfElements(); ++ihit) { - // Get a 3D hit from the list of hits + // Get a 3D hit from the list of hits EVENT::TrackerRawData* rawTracker_hit = static_cast(raw_svt_hits->getElementAt(ihit)); //Decode the cellid @@ -102,11 +103,12 @@ void SvtRawDataProcessor::process(IEvent* ievent) { } // Add the raw hit collection to the event - event->addCollection(Collections::RAW_SVT_HITS, rawhits_); + event->addCollection(Collections::RAW_SVT_HITS, rawhits_); //Clean up if (hasFits) delete rawTracker_hit_fits_nav; + return true; } void SvtRawDataProcessor::finalize() { diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx new file mode 100644 index 000000000..4c39c2292 --- /dev/null +++ b/processors/src/TrackingProcessor.cxx @@ -0,0 +1,280 @@ + +#include "TrackingProcessor.h" + +TrackingProcessor::TrackingProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +TrackingProcessor::~TrackingProcessor() { +} + +void TrackingProcessor::initialize(TTree* tree) { + tree->Branch(Collections::GBL_TRACKS,&tracks_); + tree->Branch(Collections::TRACKER_HITS, &hits_); + tree->Branch(Collections::RAW_SVT_HITS, &rawhits_); + +} + +bool TrackingProcessor::process(IEvent* ievent) { + + + tracks_.clear(); + hits_.clear(); + rawhits_.clear(); + + Event* event = static_cast (ievent); + // Get the collection of 3D hits from the LCIO event. If no such collection + // exist, a DataNotAvailableException is thrown + + // Get decoders to read cellids + UTIL::BitField64 decoder("system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12"); + + UTIL::LCRelationNavigator* rawTracker_hit_fits_nav = nullptr; + EVENT::LCCollection* raw_svt_hit_fits = nullptr; + //Check to see if fits are in the file + auto evColls = event->getLCEvent()->getCollectionNames(); + auto it = std::find (evColls->begin(), evColls->end(), Collections::RAW_SVT_HIT_FITS); + bool hasFits = true; + if(it == evColls->end()) hasFits = false; + if(hasFits) + { + raw_svt_hit_fits = event->getLCCollection(Collections::RAW_SVT_HIT_FITS); + // Heap an LCRelation navigator which will allow faster access + rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); + + } + + // Get all track collections from the event + EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); + + + // Loop over all the LCIO Tracks and add them to the HPS event. + for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { + + // Get a LCIO Track from the LCIO event + EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); + + // Add a track to the event + Track* track = new Track(); + + // Set the track parameters + track->setTrackParameters(lc_track->getD0(), + lc_track->getPhi(), + lc_track->getOmega(), + lc_track->getTanLambda(), + lc_track->getZ0()); + + // Set the track type + track->setType(lc_track->getType()); + + // Set the track fit chi^2 + track->setChi2(lc_track->getChi2()); + + // Set the position of the extrapolated track at the ECal face. The + // extrapolation uses the full 3D field map. + const EVENT::TrackState* track_state + = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); + double position_at_ecal[3] = { + track_state->getReferencePoint()[1], + track_state->getReferencePoint()[2], + track_state->getReferencePoint()[0] + }; + track->setPositionAtEcal(position_at_ecal); + + // Get the collection of LCRelations between GBL kink data variables + // (GBLKinkData) and the corresponding track. + EVENT::LCCollection* gbl_kink_data = + static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to GBLKinkData object + UTIL::LCRelationNavigator* gbl_kink_data_nav + = new UTIL::LCRelationNavigator(gbl_kink_data); + + // Get the list of GBLKinkData associated with the LCIO Track + EVENT::LCObjectVec gbl_kink_data_list + = gbl_kink_data_nav->getRelatedFromObjects(lc_track); + + // The container of GBLKinkData objects should only contain a + // single object. If not, throw an exception + if (gbl_kink_data_list.size() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA_REL) + + " has the wrong data structure."); + } + + // Get the list GBLKinkData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* gbl_kink_datum + = static_cast(gbl_kink_data_list.at(0)); + + // Set the lambda and phi kink values + for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { + track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); + track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); + } + + delete gbl_kink_data_nav; + + // Get the collection of LCRelations between track data variables + // (TrackData) and the corresponding track. + EVENT::LCCollection* track_data = static_cast( + event->getLCCollection(Collections::TRACK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to TrackData objects + UTIL::LCRelationNavigator* track_data_nav + = new UTIL::LCRelationNavigator(track_data); + + // Get the list of TrackData associated with the LCIO Track + EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); + + // The container of TrackData objects should only contain a single + // object. If not, throw an exception. + if (track_data_list.size() == 1) { + + // Get the TrackData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); + + // Check that the TrackData data structure is correct. If it's + // not, throw a runtime exception. + if (track_datum->getNDouble() != 14 || track_datum->getNFloat() != 1 + || track_datum->getNInt() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA) + + " has the wrong structure."); + } + + // Set the SvtTrack isolation values + for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { + track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); + } + + // Set the SvtTrack time + track->setTrackTime(track_datum->getFloatVal(0)); + + // Set the volume (top/bottom) in which the SvtTrack resides + track->setTrackVolume(track_datum->getIntVal(0)); + } + + delete track_data_nav; + + // Get the collection of 3D hits associated with a LCIO Track + EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); + + // Iterate through the collection of 3D hits (TrackerHit objects) + // associated with a track, find the corresponding hits in the HPS + // event and add references to the track + for (auto lc_tracker_hit : lc_tracker_hits) { + + + TrackerHit* tracker_hit = new TrackerHit(); + // Get the position of the LCIO TrackerHit and set the position of + // the TrackerHit + double hit_position[3] = { + lc_tracker_hit->getPosition()[0], + lc_tracker_hit->getPosition()[1], + lc_tracker_hit->getPosition()[2] + }; + tracker_hit->setPosition(hit_position, true); + + // Set the covariance matrix of the SvtHit + tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); + + // Set the time of the SvtHit + tracker_hit->setTime(lc_tracker_hit->getTime()); + + // Set the charge of the SvtHit + tracker_hit->setCharge(lc_tracker_hit->getEDep()); + + + //Get the Raw content of the tracker hits + EVENT::LCObjectVec rawHits = lc_tracker_hit->getRawHits(); + + //Return 0 + //EVENT::LCObjectVec rawHits_navigated = tracker_hits_to_raw_nav->getRelatedToObjects(lc_tracker_hit); + + if (_debug) + std::cout<<"Raw Hit Size::"<< rawHits.size()<(rawHits.at(irh)); + + EVENT::long64 value = + EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) | + ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 ); + decoder.setValue(value); + + + RawSvtHit* rawHit = new RawSvtHit(); + rawHit->setSystem(decoder["system"]); + rawHit->setBarrel(decoder["barrel"]); + rawHit->setLayer(decoder["layer"]); + rawHit->setModule(decoder["module"]); + rawHit->setSensor(decoder["sensor"]); + rawHit->setSide(decoder["side"]); + rawHit->setStrip(decoder["strip"]); + + // Extract ADC values for this hit + int hit_adcs[6] = { + (int)rawTracker_hit->getADCValues().at(0), + (int)rawTracker_hit->getADCValues().at(1), + (int)rawTracker_hit->getADCValues().at(2), + (int)rawTracker_hit->getADCValues().at(3), + (int)rawTracker_hit->getADCValues().at(4), + (int)rawTracker_hit->getADCValues().at(5)}; + + rawHit->setADCs(hit_adcs); + + if (hasFits) + { + // Get the list of fit params associated with the raw tracker hit + EVENT::LCObjectVec rawTracker_hit_fits_list + = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); + + // Get the list SVTFittedRawTrackerHit GenericObject associated with the SVTRawTrackerHit + IMPL::LCGenericObjectImpl* hit_fit_param + = static_cast(rawTracker_hit_fits_list.at(0)); + + double fit_params[5] = { + (double)hit_fit_param->getDoubleVal(0), + (double)hit_fit_param->getDoubleVal(1), + (double)hit_fit_param->getDoubleVal(2), + (double)hit_fit_param->getDoubleVal(3), + (double)hit_fit_param->getDoubleVal(4) + }; + + rawHit->setFit(fit_params); + } + + tracker_hit->addRawHit(rawHit); + rawhits_.push_back(rawHit); + if (_debug) + std::cout<<"RawHit ID:"<id()<getRawHits()->GetEntries()<addHit(tracker_hit); + hits_.push_back(tracker_hit); + }//tracker hits + tracks_.push_back(track); + }// tracks + + + //event->addCollection("TracksInfo", &tracks_); + //event->addCollection("TrackerHitsInfo", &hits_); + //event->addCollection("TrackerHitsRawInfo", &rawhits_); + + + return true; +} + +void TrackingProcessor::finalize() { +} + +DECLARE_PROCESSOR(TrackingProcessor); From 275cbe6765b1ed83d26811968d731331d7e8cd86 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 5 Sep 2019 17:29:33 -0700 Subject: [PATCH 095/314] Example of rootNutple processing configuration file --- processors/config/rootNtuple_example.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 processors/config/rootNtuple_example.py diff --git a/processors/config/rootNtuple_example.py b/processors/config/rootNtuple_example.py new file mode 100644 index 000000000..18e8534a4 --- /dev/null +++ b/processors/config/rootNtuple_example.py @@ -0,0 +1,20 @@ +import HpstrConf +import sys +p = HpstrConf.Process() + +# Library containing processors +p.libraries.append("libprocessors.dylib") + +#Processors + +#event = HpstrConf.Processor('event' ,'HPSEventProcessor') +clusters = HpstrConf.Processor('clusters','ClusterOnTrackProcessor') + +p.sequence = [clusters] +#p.input_files = ["testRun.root"] +#p.input_files = ["/Users/Pierfrancesco/HPS/dataFiles/MC19/tritrig/total_tritrig_hipsterNtuples_2019.root"] +p.input_files = ["/Users/Pierfrancesco/HPS/sw/hipster/run/hps_10494.root"] +p.output_files = ["testHistograms.root"] +#p.max_events = 10 +p.printProcess() + From 677d8a260c9d8603c11e10ae99758a9ceb9fcf8c Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 5 Sep 2019 17:54:47 -0700 Subject: [PATCH 096/314] Fixed missing closing of the file --- processors/src/ClusterOnTrackProcessor.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/processors/src/ClusterOnTrackProcessor.cxx b/processors/src/ClusterOnTrackProcessor.cxx index c3c0e1ad0..882480a67 100644 --- a/processors/src/ClusterOnTrackProcessor.cxx +++ b/processors/src/ClusterOnTrackProcessor.cxx @@ -34,6 +34,7 @@ bool ClusterOnTrackProcessor::process(IEvent* ievent) { void ClusterOnTrackProcessor::finalize() { clusterHistos->saveHistos(outF_,""); + outF_->Close(); } From 7a23c3453813f2b8b9cc84cfcc0331b69fdd0853 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 10 Sep 2019 09:04:55 -0700 Subject: [PATCH 097/314] Refit track processor --- processors/include/RefittedTracksProcessor.h | 93 +++++++++++ processors/src/RefittedTracksProcessor.cxx | 158 +++++++++++++++++++ 2 files changed, 251 insertions(+) create mode 100644 processors/include/RefittedTracksProcessor.h create mode 100644 processors/src/RefittedTracksProcessor.cxx diff --git a/processors/include/RefittedTracksProcessor.h b/processors/include/RefittedTracksProcessor.h new file mode 100644 index 000000000..39ecfa189 --- /dev/null +++ b/processors/include/RefittedTracksProcessor.h @@ -0,0 +1,93 @@ +/** + * + */ + +#ifndef __REFITTEDTRACKS_PROCESSOR_H__ +#define __REFITTEDTRACKS_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "Track.h" +#include "Event.h" + +// Forward declarations +class TTree; + +class RefittedTracksProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + RefittedTracksProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~RefittedTracksProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual bool process(IEvent* ievent); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(TTree* tree); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Container to hold all Track objects. */ + std::vector tracks_{}; + + /** Container to hold all Track objects. */ + std::vector refit_tracks_{}; + + bool _debug{false}; + + + + + +}; // Refitted Tracks Processor + +#endif // __REFITTEDTRACKS_PROCESSOR_ diff --git a/processors/src/RefittedTracksProcessor.cxx b/processors/src/RefittedTracksProcessor.cxx new file mode 100644 index 000000000..cf666bc37 --- /dev/null +++ b/processors/src/RefittedTracksProcessor.cxx @@ -0,0 +1,158 @@ +#include "RefittedTracksProcessor.h" + +RefittedTracksProcessor::RefittedTracksProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +RefittedTracksProcessor::~RefittedTracksProcessor() { +} + +void RefittedTracksProcessor::initialize(TTree* tree) { + tree->Branch(Collections::GBL_TRACKS,&tracks_); + tree->Branch("GBLRefittedTracks", &refit_tracks_); + +} + +bool RefittedTracksProcessor::process(IEvent* ievent) { + + Event* event = static_cast (ievent); + //Get all ethe tracks + EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); + + // Loop over all the LCIO Tracks and add them to the HPS event. + for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { + + // Get a LCIO Track from the LCIO event + EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); + + // Add a track to the event + Track* track = new Track(); + + // Set the track parameters + track->setTrackParameters(lc_track->getD0(), + lc_track->getPhi(), + lc_track->getOmega(), + lc_track->getTanLambda(), + lc_track->getZ0()); + + // Set the track type + track->setType(lc_track->getType()); + + // Set the track fit chi^2 + track->setChi2(lc_track->getChi2()); + + // Set the position of the extrapolated track at the ECal face. The + // extrapolation uses the full 3D field map. + const EVENT::TrackState* track_state + = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); + double position_at_ecal[3] = { + track_state->getReferencePoint()[1], + track_state->getReferencePoint()[2], + track_state->getReferencePoint()[0] + }; + track->setPositionAtEcal(position_at_ecal); + + // Get the collection of LCRelations between GBL kink data variables + // (GBLKinkData) and the corresponding track. + EVENT::LCCollection* gbl_kink_data = + static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to GBLKinkData object + UTIL::LCRelationNavigator* gbl_kink_data_nav + = new UTIL::LCRelationNavigator(gbl_kink_data); + + // Get the list of GBLKinkData associated with the LCIO Track + EVENT::LCObjectVec gbl_kink_data_list + = gbl_kink_data_nav->getRelatedFromObjects(lc_track); + + // The container of GBLKinkData objects should only contain a + // single object. If not, throw an exception + if (gbl_kink_data_list.size() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA_REL) + + " has the wrong data structure."); + } + + // Get the list GBLKinkData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* gbl_kink_datum + = static_cast(gbl_kink_data_list.at(0)); + + // Set the lambda and phi kink values + for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { + track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); + track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); + } + + delete gbl_kink_data_nav; + + // Get the collection of LCRelations between track data variables + // (TrackData) and the corresponding track. + EVENT::LCCollection* track_data = static_cast( + event->getLCCollection(Collections::TRACK_DATA_REL)); + + // Instantiate an LCRelation navigator which will allow faster access + // to TrackData objects + UTIL::LCRelationNavigator* track_data_nav + = new UTIL::LCRelationNavigator(track_data); + + // Get the list of TrackData associated with the LCIO Track + EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); + + // The container of TrackData objects should only contain a single + // object. If not, throw an exception. + if (track_data_list.size() == 1) { + + // Get the TrackData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); + + // Check that the TrackData data structure is correct. If it's + // not, throw a runtime exception. + if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 + || track_datum->getNInt() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA) + + " has the wrong structure."); + } + + // Set the SvtTrack isolation values + for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { + track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); + } + + // Set the SvtTrack time + track->setTrackTime(track_datum->getFloatVal(0)); + + // Set the volume (top/bottom) in which the SvtTrack resides + track->setTrackVolume(track_datum->getIntVal(0)); + } + delete track_data_nav; + + + //Get the refitted tracks relations + + EVENT::LCCollection* refitted_tracks_rel = + static_cast(event->getLCCollection("GBLTrackToGBLTrackRefitRelations")); + + //Build the navigator + UTIL::LCRelationNavigator* refitted_tracks_nav = new UTIL::LCRelationNavigator(refitted_tracks_rel); + + //Get the list of data + EVENT::LCObjectVec refitted_tracks_list = refitted_tracks_nav -> getRelatedFromObjects(lc_track); + + //print the size! + //std::cout<<"For track: "< Date: Tue, 10 Sep 2019 13:17:42 -0700 Subject: [PATCH 098/314] RefittedTracksProcessor: printout refit track properties --- processors/src/RefittedTracksProcessor.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/processors/src/RefittedTracksProcessor.cxx b/processors/src/RefittedTracksProcessor.cxx index cf666bc37..ef1785952 100644 --- a/processors/src/RefittedTracksProcessor.cxx +++ b/processors/src/RefittedTracksProcessor.cxx @@ -1,4 +1,5 @@ #include "RefittedTracksProcessor.h" +#include RefittedTracksProcessor::RefittedTracksProcessor(const std::string& name, Process& process) : Processor(name, process) { @@ -136,15 +137,19 @@ bool RefittedTracksProcessor::process(IEvent* ievent) { //Build the navigator UTIL::LCRelationNavigator* refitted_tracks_nav = new UTIL::LCRelationNavigator(refitted_tracks_rel); + //Get the list of data - EVENT::LCObjectVec refitted_tracks_list = refitted_tracks_nav -> getRelatedFromObjects(lc_track); - - //print the size! - //std::cout<<"For track: "< getRelatedToObjects(lc_track); + + std::cout<< std::fixed << std::setw( 11 ) << std::setprecision( 6 )<getD0()<<" " <getPhi()<<" "<getOmega()<<" "<getTanLambda()<<" "<getZ0()<(refitted_tracks_list.at(irtrk)); + std::cout<<"Refitted tracks params: "<getD0()<<" " << rfit_track->getPhi()<<" "<getOmega()<<" "<getTanLambda()<<" "<getZ0()< Date: Mon, 16 Sep 2019 13:46:56 -0700 Subject: [PATCH 099/314] Remove include of any lib in Event.h --- event/include/Event.h | 1 - 1 file changed, 1 deletion(-) diff --git a/event/include/Event.h b/event/include/Event.h index 724854c4c..08030880f 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -12,7 +12,6 @@ // C++ StdLib // //----------------// #include -#include //----------// // LCIO // From 01755e1b4cbb27f6a8eeed17bcc1716601c48264 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Mon, 16 Sep 2019 16:20:04 -0700 Subject: [PATCH 100/314] Check on process event return value. --- processing/src/Process.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index ec17582ec..8a3150e07 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -34,8 +34,6 @@ void Process::runOnRoot() { //In this way if the processing fails (like an event doesn't pass the selection, the other modules aren't run on that event) for (auto module : sequence_) { module->process(&event); - //if (!module->process(&event)) - //break; } //event.Clear(); ++n_events_processed; @@ -101,8 +99,10 @@ void Process::run() { if (n_events_processed%1000 == 0) std::cout << "---- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; event.Clear(); - for (auto module : sequence_) { - module->process(&event); + for (auto module : sequence_) { + //TODO: actually pass the flag to the filling of the tree + if (!module->process(&event)) + break; } ++n_events_processed; } From bb5e55c75cf151883f1bf617a1b6968a656290bd Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Mon, 16 Sep 2019 16:25:43 -0700 Subject: [PATCH 101/314] Added histogramming classes --- analysis/include/HistoManager.h | 6 +- analysis/include/TrackHistos.h | 38 +++++++ analysis/src/ClusterHistos.cxx | 30 ++++-- analysis/src/HistoManager.cxx | 3 +- analysis/src/TrackHistos.cxx | 174 ++++++++++++++++++++++++++++++++ 5 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 analysis/include/TrackHistos.h create mode 100644 analysis/src/TrackHistos.cxx diff --git a/analysis/include/HistoManager.h b/analysis/include/HistoManager.h index dd07e8d7b..bb93c7447 100644 --- a/analysis/include/HistoManager.h +++ b/analysis/include/HistoManager.h @@ -70,10 +70,12 @@ class HistoManager { virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder = ""); - virtual void saveHistos(TFile* outF,std::string folder); + virtual void saveHistos(TFile* outF = nullptr,std::string folder = ""); virtual void sumw2(); + void debugMode(bool debug) {debug_ = debug;} + protected: std::string m_name; @@ -89,7 +91,7 @@ class HistoManager { std::map histos3d; typedef std::map::iterator it3d; - + bool debug_{false}; }; diff --git a/analysis/include/TrackHistos.h b/analysis/include/TrackHistos.h new file mode 100644 index 000000000..6e64c41a8 --- /dev/null +++ b/analysis/include/TrackHistos.h @@ -0,0 +1,38 @@ +#ifndef TRACKHISTOS_H +#define TRACKHISTOS_H + +#include "HistoManager.h" +#include "Track.h" +#include +#include + +class TrackHistos : public HistoManager { + + public: + + TrackHistos(const std::string& inputName) : + HistoManager(inputName) + {m_name = inputName; + BuildAxes(); + } + + virtual void Define3DHistos(){}; + virtual void Define2DHistos(); + virtual void Define1DHistos(); + + void BuildAxes(); + + void Fill1DHistograms(Track* track, float weight = 1.); + + //track_x goes for x axis, and y for y axis + void FillTrackComparisonHistograms(Track* track_x, Track* track_y, float weight = 1.); + void doTrackComparisonPlots(bool doplots) {doTrkCompPlots = doplots;}; + + private: + std::vector tPs{"d0","Phi","Omega","TanLambda","Z0","time","chi2"}; + std::map > axes; + bool doTrkCompPlots{false}; + +}; + +#endif //TRACKHISTOS_H diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx index 329977a8b..355a2b726 100644 --- a/analysis/src/ClusterHistos.cxx +++ b/analysis/src/ClusterHistos.cxx @@ -29,15 +29,23 @@ void ClusterHistos::Define1DHistos() { void ClusterHistos::Define2DHistos() { std::string h_name = ""; - histos2d[m_name+"_charge_vs_gx"] = plot2D(m_name+"_charge_vs_gx", + histos2d[m_name+"_charge_L0_top_vs_gx"] = plot2D(m_name+"_charge_L0_top_vs_gx", "Global X [mm] ",100,0,100, "edep",100,0,10000); int nbins = 1000; - float pitch = 0.055; + float pitch = 0.050; - histos2d[m_name+"_charge_vs_gy"] = plot2D(m_name+"_charge_vs_gy", - "Gloabl Y [mm]",nbins,0.750,(nbins+1)*0.055, - "edep",100,0,10000); + histos2d[m_name+"_charge_L0_top_vs_gy"] = plot2D(m_name+"_charge_L0_top_vs_gy", + "Global Y [mm]",nbins,0.700,(nbins+1)*pitch, + "edep",100,0,10000); + + + histos2d[m_name+"_charge_L0_bottom_vs_gx"] = plot2D(m_name+"_charge_L0_bottom_vs_gx", + "Global X [mm] ",100,0,100, + "edep",100,0,10000); + histos2d[m_name+"_charge_L0_top_vs_gy"] = plot2D(m_name+"_charge_L0_bottom_vs_gy", + "Global Y [mm]",nbins,0.700,(nbins+1)*pitch, + "edep",100,0,10000); for (unsigned int iv = 0 ; iv < volumes.size(); ++iv) { for (unsigned int ily = 0; ily < layers.size(); ++ily) { @@ -136,6 +144,14 @@ void ClusterHistos::FillHistograms(TrackerHit* hit,float weight) { //1D //histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); //2D - //histos2d[m_name+"_charge_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); - //histos2d[m_name+"_charge_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); + if (hit->getGlobalZ() < 50 && hit->getGlobalZ() > 40) { + histos2d[m_name+"_charge_L0_top_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0_top_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); + } + + if (hit->getGlobalZ() < 60 && hit->getGlobalZ() > 55) { + histos2d[m_name+"_charge_L0_bottom_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0_bottom_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); + } + } diff --git a/analysis/src/HistoManager.cxx b/analysis/src/HistoManager.cxx index bb6278cd8..ec5465dc9 100644 --- a/analysis/src/HistoManager.cxx +++ b/analysis/src/HistoManager.cxx @@ -167,7 +167,8 @@ void HistoManager::sumw2() { void HistoManager::saveHistos(TFile* outF,std::string folder) { - outF->cd(); + if (outF) + outF->cd(); TDirectoryFile* dir = 0; if (!folder.empty()) { diff --git a/analysis/src/TrackHistos.cxx b/analysis/src/TrackHistos.cxx new file mode 100644 index 000000000..25b4c293f --- /dev/null +++ b/analysis/src/TrackHistos.cxx @@ -0,0 +1,174 @@ +#include "TrackHistos.h" +#include + +void TrackHistos::Define1DHistos() { + + //TODO improve naming + std::string h_name = ""; + + for (unsigned int itp = 0; itpGetXaxis()->SetBinLabel(i,labels[i-1].c_str()); + + histos1d[m_name+"_type" ] = plot1D(m_name+"_type", + "Type",64,0,64); + + histos1d[m_name+"_nShared"] = plot1D(m_name+"_nShared", + "nShared Hits",8,-0.5,7.5); + histos1d[m_name+"_sharingHits"] = plot1D(m_name+"_sharingHits", + "sharingHits",6,-0.5,5.5); + + labels[0]="All Tracks"; + labels[1]="nShared = 0"; + labels[2]="SharedLy0"; + labels[3]="SharedLy1"; + labels[4]="SharedLy0AndLy1"; + labels[5]="Shared Others"; + + + for (int i = 1; i<=nbinsX; ++i) + histos1d[m_name+"_sharingHits"]->GetXaxis()->SetBinLabel(i,labels[i-1].c_str()); + + + //Hit content + //shared hits + //location of hit in first layer + //Total charge of hit in first layer + //size of hit in first layer + + + +} + + +void TrackHistos::BuildAxes() { + + axes["d0"].push_back(200); + axes["d0"].push_back(-10); + axes["d0"].push_back(10); + + axes["Phi"].push_back(100); + axes["Phi"].push_back(-0.5); + axes["Phi"].push_back(0.5); + + axes["Omega"].push_back(100); + axes["Omega"].push_back(-0.002); + axes["Omega"].push_back(0.002); + + axes["TanLambda"].push_back(200); + axes["TanLambda"].push_back(-0.6); + axes["TanLambda"].push_back(0.6); + + axes["Z0"].push_back(200); + axes["Z0"].push_back(-20); + axes["Z0"].push_back(20); + + axes["time"].push_back(200); + axes["time"].push_back(-10); + axes["time"].push_back(10); + + axes["chi2"].push_back(200); + axes["chi2"].push_back(0); + axes["chi2"].push_back(30); +} + + + +void TrackHistos::Define2DHistos() { + + //TODO improve naming + std::string h_name = ""; + + //TODO improve binning + if (doTrkCompPlots) { + + for (unsigned int itp = 0; itpFill(track->getD0() ,weight); + histos1d[m_name+"_Phi" ]->Fill(track->getPhi() ,weight); + histos1d[m_name+"_Omega" ]->Fill(track->getOmega() ,weight); + histos1d[m_name+"_TanLambda"]->Fill(track->getTanLambda() ,weight); + histos1d[m_name+"_Z0" ]->Fill(track->getZ0() ,weight); + histos1d[m_name+"_time" ]->Fill(track->getTrackTime() ,weight); + histos1d[m_name+"_chi2" ]->Fill(track->getChi2Ndf() ,weight); + histos1d[m_name+"_nShared" ]->Fill(track->getNShared() ,weight); + + //All Tracks + histos1d[m_name+"_sharingHits"]->Fill(0.,weight); + if (track->getNShared() == 0) + histos1d[m_name+"_sharingHits"]->Fill(1.,weight); + else { + //track has shared hits + if (track->getSharedLy0()) + histos1d[m_name+"_sharingHits"]->Fill(2.,weight); + if (track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(3.,weight); + if (track->getSharedLy0() && track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(4.,weight); + if (!track->getSharedLy0() && !track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(5.,weight); + } + + + //TODO improve this + if (track -> is345Seed()) + histos1d[m_name+"_strategy"]->Fill(0); + if (track-> is456Seed()) + histos1d[m_name+"_strategy"]->Fill(1); + if (track-> is123SeedC4()) + histos1d[m_name+"_strategy"]->Fill(2); + if (track->is123SeedC5()) + histos1d[m_name+"_strategy"]->Fill(3); + if (track->isMatchedTrack()) + histos1d[m_name+"_strategy"]->Fill(4); + if (track->isGBLTrack()) + histos1d[m_name+"_strategy"]->Fill(5); + + histos1d[m_name+"_type" ]->Fill(track->getType() ,weight); +} + + + +void TrackHistos::FillTrackComparisonHistograms(Track* track_x, Track* track_y, float weight) { + + if (doTrkCompPlots) { + histos2d[m_name+"_d0_vs_d0" ]->Fill(track_x->getD0(),track_y->getD0(),weight); + histos2d[m_name+"_Phi_vs_Phi" ]->Fill(track_x->getPhi(),track_y->getPhi(),weight); + histos2d[m_name+"_Omega_vs_Omega" ]->Fill(track_x->getOmega(),track_y->getOmega(),weight); + histos2d[m_name+"_TanLambda_vs_TanLambda"]->Fill(track_x->getTanLambda(),track_y->getTanLambda(),weight); + histos2d[m_name+"_Z0_vs_Z0" ]->Fill(track_x->getZ0(),track_y->getZ0(),weight); + histos2d[m_name+"_time_vs_time" ]->Fill(track_x->getTrackTime(),track_y->getTrackTime(),weight); + histos2d[m_name+"_chi2_vs_chi2" ]->Fill(track_x->getChi2Ndf(), + track_y->getChi2Ndf(), + weight); + } +} + + + From 722953b0f04faf57e8529af921680fd8357101d8 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Mon, 16 Sep 2019 16:30:32 -0700 Subject: [PATCH 102/314] Added utilities functions to build objects --- processors/include/utilities.h | 52 ++++++ processors/src/utilities.cxx | 291 +++++++++++++++++++++++++++++++++ 2 files changed, 343 insertions(+) create mode 100644 processors/include/utilities.h create mode 100644 processors/src/utilities.cxx diff --git a/processors/include/utilities.h b/processors/include/utilities.h new file mode 100644 index 000000000..4b21e3ded --- /dev/null +++ b/processors/include/utilities.h @@ -0,0 +1,52 @@ +#ifndef _UTILITIES_ +#define _UTILITIES_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "Track.h" +#include "RawSvtHit.h" +#include "Event.h" +#include "TrackerHit.h" + +namespace utils { + + Track* buildTrack(EVENT::Track* lc_track, + EVENT::LCCollection* gbl_kink_data, + EVENT::LCCollection* track_data); + + RawSvtHit* buildRawHit(EVENT::TrackerRawData* rawTracker_hit, + EVENT::LCCollection* raw_svt_hit_fits); + + TrackerHit* buildTrackerHit(IMPL::TrackerHitImpl* lc_trackerHit); + bool addRawInfoTo3dHit(TrackerHit* tracker_hit, + IMPL::TrackerHitImpl* lc_tracker_hit, + EVENT::LCCollection* raw_svt_fits); + + + bool isUsedByTrack(IMPL::TrackerHitImpl* lc_tracker_hit, + EVENT::Track* lc_track); + + bool isUsedByTrack(TrackerHit* tracker_hit, + EVENT::Track* lc_track); + + + //TODO: extern? + static UTIL::BitField64 decoder("system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12"); + +} + + +#endif //UTILITIES diff --git a/processors/src/utilities.cxx b/processors/src/utilities.cxx new file mode 100644 index 000000000..b9528b2a1 --- /dev/null +++ b/processors/src/utilities.cxx @@ -0,0 +1,291 @@ +#include "utilities.h" +#include +/* +void utils::buildTrackCollection(std::vector& tracks, + Event* event, + const char* LCTrackCollection) +{ + + EVENT::LCCollection* lc_tracks event->getLCCollection(LCTrackCollection); + + +} + +*/ + +Track* utils::buildTrack(EVENT::Track* lc_track, + EVENT::LCCollection* gbl_kink_data, + EVENT::LCCollection* track_data) { + + if (!lc_track) + return nullptr; + + Track* track = new Track(); + // Set the track parameters + track->setTrackParameters(lc_track->getD0(), + lc_track->getPhi(), + lc_track->getOmega(), + lc_track->getTanLambda(), + lc_track->getZ0()); + + // Set the track type + track->setType(lc_track->getType()); + + // Set the track fit chi^2 + track->setChi2(lc_track->getChi2()); + + // Set the track ndf + track->setNdf(lc_track->getNdf()); + + // Set the position of the extrapolated track at the ECal face. The + // extrapolation uses the full 3D field map. + const EVENT::TrackState* track_state + = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); + + if (track_state) { + double position_at_ecal[3] = { + track_state->getReferencePoint()[1], + track_state->getReferencePoint()[2], + track_state->getReferencePoint()[0] + }; + track->setPositionAtEcal(position_at_ecal); + } + + if (gbl_kink_data) { + // Instantiate an LCRelation navigator which will allow faster access + // to GBLKinkData object + UTIL::LCRelationNavigator* gbl_kink_data_nav + = new UTIL::LCRelationNavigator(gbl_kink_data); + + // Get the list of GBLKinkData associated with the LCIO Track + EVENT::LCObjectVec gbl_kink_data_list + = gbl_kink_data_nav->getRelatedFromObjects(lc_track); + + // The container of GBLKinkData objects should only contain a + // single object. If not, throw an exception + if (gbl_kink_data_list.size() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA_REL) + + " has the wrong data structure."); + } + + // Get the list GBLKinkData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* gbl_kink_datum + = static_cast(gbl_kink_data_list.at(0)); + + // Set the lambda and phi kink values + for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { + track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); + track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); + } + + delete gbl_kink_data_nav; + + } // add gbl kink data + + if (track_data) { + + // Instantiate an LCRelation navigator which will allow faster access + // to TrackData objects + UTIL::LCRelationNavigator* track_data_nav + = new UTIL::LCRelationNavigator(track_data); + + // Get the list of TrackData associated with the LCIO Track + EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); + + // The container of TrackData objects should only contain a single + // object. If not, throw an exception. + if (track_data_list.size() == 1) { + + // Get the TrackData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); + + // Check that the TrackData data structure is correct. If it's + // not, throw a runtime exception. + if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 + || track_datum->getNInt() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA) + + " has the wrong structure."); + } + + // Set the SvtTrack isolation values + for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { + track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); + } + + // Set the SvtTrack time + track->setTrackTime(track_datum->getFloatVal(0)); + + // Set the volume (top/bottom) in which the SvtTrack resides + track->setTrackVolume(track_datum->getIntVal(0)); + } + delete track_data_nav; + + } //add track data + + return track; +} + +RawSvtHit* utils::buildRawHit(EVENT::TrackerRawData* rawTracker_hit, + EVENT::LCCollection* raw_svt_hit_fits) { + + EVENT::long64 value = + EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) | + ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 ); + decoder.setValue(value); + + RawSvtHit* rawHit = new RawSvtHit(); + rawHit->setSystem(decoder["system"]); + rawHit->setBarrel(decoder["barrel"]); + rawHit->setLayer(decoder["layer"]); + rawHit->setModule(decoder["module"]); + rawHit->setSensor(decoder["sensor"]); + rawHit->setSide(decoder["side"]); + rawHit->setStrip(decoder["strip"]); + + // Extract ADC values for this hit + int hit_adcs[6] = { + (int)rawTracker_hit->getADCValues().at(0), + (int)rawTracker_hit->getADCValues().at(1), + (int)rawTracker_hit->getADCValues().at(2), + (int)rawTracker_hit->getADCValues().at(3), + (int)rawTracker_hit->getADCValues().at(4), + (int)rawTracker_hit->getADCValues().at(5)}; + + rawHit->setADCs(hit_adcs); + if (raw_svt_hit_fits) { + UTIL::LCRelationNavigator* rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); + + // Get the list of fit params associated with the raw tracker hit + EVENT::LCObjectVec rawTracker_hit_fits_list + = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); + + // Get the list SVTFittedRawTrackerHit GenericObject associated with the SVTRawTrackerHit + IMPL::LCGenericObjectImpl* hit_fit_param + = static_cast(rawTracker_hit_fits_list.at(0)); + + double fit_params[5] = { + (double)hit_fit_param->getDoubleVal(0), + (double)hit_fit_param->getDoubleVal(1), + (double)hit_fit_param->getDoubleVal(2), + (double)hit_fit_param->getDoubleVal(3), + (double)hit_fit_param->getDoubleVal(4) + }; + + rawHit->setFit(fit_params); + }//raw svt hits + + return rawHit; + +}//build raw hit + + +TrackerHit* utils::buildTrackerHit(IMPL::TrackerHitImpl* lc_tracker_hit) { + + if (!lc_tracker_hit) + return nullptr; + + TrackerHit* tracker_hit = new TrackerHit(); + + // Get the position of the LCIO TrackerHit and set the position of + // the TrackerHit + double hit_position[3] = { + lc_tracker_hit->getPosition()[0], + lc_tracker_hit->getPosition()[1], + lc_tracker_hit->getPosition()[2] + }; + tracker_hit->setPosition(hit_position, true); + + // Set the covariance matrix of the SvtHit + tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); + + // Set the time of the SvtHit + tracker_hit->setTime(lc_tracker_hit->getTime()); + + // Set the charge of the SvtHit + tracker_hit->setCharge(lc_tracker_hit->getEDep()); + + // Set the LCIO id + tracker_hit->setID(lc_tracker_hit->id()); + + return tracker_hit; + + +} + +bool utils::addRawInfoTo3dHit(TrackerHit* tracker_hit, + IMPL::TrackerHitImpl* lc_tracker_hit, + EVENT::LCCollection* raw_svt_fits) { + + if (!tracker_hit || !lc_tracker_hit) + return false; + + float rawcharge = 0; + //0 top 1 bottom + int volume = -1; + //1-6 + int layer = -1; + + //Get the Raw content of the tracker hits + EVENT::LCObjectVec rawHits = lc_tracker_hit->getRawHits(); + + for (unsigned int irh = 0 ; irh < rawHits.size(); ++irh) { + + //TODO useless to build all of it? + RawSvtHit* rawHit = buildRawHit(static_cast(rawHits.at(irh)),raw_svt_fits); + rawcharge += rawHit->getAmp(); + int currentHitVolume = rawHit->getModule() % 2 ? 1 : 0; + int currentHitLayer = (rawHit->getLayer() - 1 ) / 2; + if (volume == -1 ) + volume = currentHitVolume; + else { + if ( currentHitVolume != volume) + std::cout<<"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent volume found" <addRawHit(rawHit); + + } + + tracker_hit->setRawCharge(rawcharge); + tracker_hit->setVolume(volume); + tracker_hit->setLayer(layer); + + return true; +} + +//TODO-improve shared finding algorithm + +bool utils::isUsedByTrack(IMPL::TrackerHitImpl* lc_tracker_hit, + EVENT::Track* lc_track) { + + EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); + + for (auto trk_lc_tracker_hit : trk_lc_tracker_hits) { + //std::cout<id()<<" " <id()< id() == trk_lc_tracker_hit -> id()) + return true; + } + return false; +} + +bool utils::isUsedByTrack(TrackerHit* tracker_hit, + EVENT::Track* lc_track) { + + EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); + + for (auto trk_lc_tracker_hit : trk_lc_tracker_hits) { + if (tracker_hit->getID() == trk_lc_tracker_hit->id()) + return true; + } + return false; +} From ddbadbdf1540c0d2ec4fe0f350c09990641d971f Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Mon, 16 Sep 2019 16:33:11 -0700 Subject: [PATCH 103/314] Changes to hipster objects. Tracker hit to be completed --- event/include/Track.h | 85 ++++++++++++++++++++++++++++++++++---- event/include/TrackerHit.h | 50 ++++++++++++++++++++-- event/src/Track.cxx | 6 +++ 3 files changed, 129 insertions(+), 12 deletions(-) diff --git a/event/include/Track.h b/event/include/Track.h index e6344b8a3..d0504c2db 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -21,6 +21,11 @@ #include #include +//TODO static? +namespace TRACKINFO { + enum STRATEGY {MATCH = 0, S345, S456, S123C4, S123C5, GBL}; +} + class Track : public TObject { public: @@ -40,14 +45,13 @@ class Track : public TObject { * @param hit : A TrackerHit object */ void addHit(TObject* hit); - - /** @return A reference to the hits associated with this track. */ + + /** + * @return A reference to the hits associated with this track. + */ TRefArray* getSvtHits() const { return tracker_hits_; }; - /** @return Number of 3D hits associated with this track */ - int getNSvtHits() const { return n_hits_;} - - /** + /** * Set the track parameters. * * @param d0 Distance of closest approach to the reference point. @@ -67,6 +71,17 @@ class Track : public TObject { /** @return The track parameters. */ std::vector getTrackParameters(); + + double getD0 () const {return d0_;}; + double getPhi () const {return phi0_;}; + double getOmega () const {return omega_;}; + double getTanLambda() const {return tan_lambda_;}; + double getZ0 () const {return z0_;}; + + + void setNdf(const float ndf) {ndf_ = ndf;}; + double getNdf() const {return ndf_;}; + /** * Set the chi^2 of the fit to the track. * @@ -77,6 +92,15 @@ class Track : public TObject { /** @return the chi^2 of the fit to the track. */ double getChi2() const { return chi2_; }; + /** @return the chi^2 / ndf of the fit to the track. */ + double getChi2Ndf() const { + //avoid check for 0 + if (ndf_ > 1e-6) + return chi2_; + else + return -999; + }; + /** * Set the isolation variable of the given layer. * @@ -145,7 +169,23 @@ class Track : public TObject { /** @return The track type. */ int getType() const { return type_; }; - + /** @return The track decoded type: GSSSSM. */ + + //bit1 + bool is345Seed () const { return ((type_ >> 1) & 0x1);} + + bool is456Seed () const { return ((type_ >> 2) & 0x1);} + + bool is123SeedC4 () const { return ((type_ >> 3) & 0x1);} + + bool is123SeedC5 () const { return ((type_ >> 4) & 0x1);} + + bool isMatchedTrack() const { return (type_ & 0x1);} + + bool isGBLTrack () const { return ((type_ >> 5) & 0x1);} + + bool isStrategy(TRACKINFO::STRATEGY strategy) {return (type_ >> strategy) & 0x1;}; + /** * Set the track charge. * @@ -218,6 +258,22 @@ class Track : public TObject { */ int getTrackerHitCount() const { return n_hits_; }; + /** Set number of shared 3D hits */ + void setNShared(const int nShared) { nShared_ = nShared;}; + + int getNShared() const {return nShared_;}; + + void setSharedLy0(const bool isShared) {SharedLy0_ = isShared;}; + void setSharedLy1(const bool isShared) {SharedLy1_ = isShared;}; + + bool getSharedLy0() const {return SharedLy0_;}; + bool getSharedLy1() const {return SharedLy1_;}; + + + //TODO doc + + void Print (Option_t *option="") const; + private: /** Reference to the 3D hits associated with this track. */ @@ -268,6 +324,9 @@ class Track : public TObject { /** The chi^2 of the track fit. */ double chi2_{-999}; + /** The ndfs of the track fit. */ + double ndf_{0.}; + /** * The time of the track. This is currently the average time of all * hits composing the track. @@ -295,8 +354,18 @@ class Track : public TObject { double pz_{-9999}; /** Track charge. */ - int charge_{0}; + int charge_{0}; + + /** N Shared hits. */ + int nShared_{0}; + + /** Has Ly0 Shared hits. */ + bool SharedLy0_{false}; + + /** Has Ly1 Shared hits. */ + bool SharedLy1_{false}; + ClassDef(Track, 1); }; // Track diff --git a/event/include/TrackerHit.h b/event/include/TrackerHit.h index c4907732e..792332c62 100644 --- a/event/include/TrackerHit.h +++ b/event/include/TrackerHit.h @@ -82,16 +82,40 @@ class TrackerHit : public TObject { */ void setCharge(const double charge) { charge_ = charge; }; - /** @return The hit time. */ + /** @return The hit charge. */ double getCharge() const { return charge_; }; + void setRawCharge(const double rawcharge) { rawcharge_ = rawcharge; }; + + /** @return The hit charge. */ + double getRawCharge() const { return rawcharge_; }; + + void setVolume(const int volume ) {volume_ = volume;} ; + + //** @return the tracker hit volume from the raw hit content */ + int getVolume() { return volume_;} ; + + //** set the tracker hit layer from the raw hit content */ + void setLayer(const int layer) {layer_ = layer;}; + + //** @return the tracker hit layer from the raw hit content */ + int getLayer() const {return layer_;}; - /** Add raw hit to the raw hit reference array */ + /** Is a hit shared between multiple tracks. */ + bool isShared() const ; + + /** Add raw hit to the raw hit reference array */ void addRawHit(TObject* rawhit) { ++n_rawhits_; raw_hits_->Add(rawhit); } + //TODO: I use this to get the shared hits. Not sure if useful. + /** LCIO id */ + void setID(const int id) {id_=id;}; + + int getID() const {return id_;}; + ClassDef(TrackerHit, 1); private: @@ -122,9 +146,27 @@ class TrackerHit : public TObject { /** The hit charge deposit. */ double charge_{-999}; - /** The raw hits */ + /** The raw hits */ TRefArray* raw_hits_{new TRefArray{}}; - + + /** Layer (Axial + Stereo). 1-6 in 2015/2016 geometry, 0-7 in 2019 geometry */ + int layer_{-999}; + + /** Volume 0-top 1-bottom) */ + int volume_{-999}; + + /** Raw charge: sum of the raw hit fit amplitudes */ + float rawcharge_{-999}; + + /** How many tracks share this hit */ + int shared_{-999}; + + /** LCIO id */ + int id_{-999}; + + /** Tracks that share this hit */ + TRefArray* tracks_{new TRefArray{}}; + }; // TrackerHit diff --git a/event/src/Track.cxx b/event/src/Track.cxx index c42bc65d6..d0567840c 100644 --- a/event/src/Track.cxx +++ b/event/src/Track.cxx @@ -58,3 +58,9 @@ void Track::addHit(TObject* hit) { ++n_hits_; tracker_hits_->Add(hit); } + +void Track::Print (Option_t *option) const { + printf("d0 Phi Omega TanLambda Z0 time chi2\n"); + printf("% 6.4f % 6.4f % 6.4f % 6.4f % 6.4f % 6.4f % 6.4f\n",d0_,phi0_,omega_,tan_lambda_,z0_,track_time_,chi2_); + printf("type: %d\n", type_); +} From af019f2bcd47ac63daa2b33a00fb8f77ef2e221c Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Mon, 16 Sep 2019 16:35:10 -0700 Subject: [PATCH 104/314] Fix name of output file in cluster on track processor --- processing/src/HpsEventFile.cxx | 3 ++- processing/src/Process.cxx | 3 +++ processors/src/ClusterOnTrackProcessor.cxx | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/processing/src/HpsEventFile.cxx b/processing/src/HpsEventFile.cxx index 741d75a7c..866c091bb 100644 --- a/processing/src/HpsEventFile.cxx +++ b/processing/src/HpsEventFile.cxx @@ -22,7 +22,8 @@ void HpsEventFile::setupEvent(IEvent* ievent) { } void HpsEventFile::close() { - + rootfile_->cd(); + rootfile_->Close(); ofile_->cd(); ofile_->Close(); diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 8a3150e07..dbfd102ab 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -41,6 +41,9 @@ void Process::runOnRoot() { //Pass to next file ++cfile; // Finalize all modules + + //Select the output file for storing the results of the processors. + file->resetOutputFileDir(); for (auto module : sequence_) { //TODO:Change the finalize method module->finalize(); diff --git a/processors/src/ClusterOnTrackProcessor.cxx b/processors/src/ClusterOnTrackProcessor.cxx index 882480a67..54319d0cd 100644 --- a/processors/src/ClusterOnTrackProcessor.cxx +++ b/processors/src/ClusterOnTrackProcessor.cxx @@ -13,7 +13,7 @@ void ClusterOnTrackProcessor::initialize(TTree* tree) { //TODO Change this. tree_->SetBranchAddress("GBLTracks",&tracks_,&btracks_); //TODO Change this. - outF_ = new TFile("outputFile.root","recreate"); + //outF_ = new TFile("outputFile.root","recreate"); } @@ -34,7 +34,7 @@ bool ClusterOnTrackProcessor::process(IEvent* ievent) { void ClusterOnTrackProcessor::finalize() { clusterHistos->saveHistos(outF_,""); - outF_->Close(); + //outF_->Close(); } From 11d7fb8c147f00296c2a41d881cbaa0b83653b61 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Mon, 16 Sep 2019 16:36:24 -0700 Subject: [PATCH 105/314] Track data valid for older geometry --- processors/src/TrackingProcessor.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx index 4c39c2292..b5a192085 100644 --- a/processors/src/TrackingProcessor.cxx +++ b/processors/src/TrackingProcessor.cxx @@ -137,7 +137,7 @@ bool TrackingProcessor::process(IEvent* ievent) { // Check that the TrackData data structure is correct. If it's // not, throw a runtime exception. - if (track_datum->getNDouble() != 14 || track_datum->getNFloat() != 1 + if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 || track_datum->getNInt() != 1) { throw std::runtime_error("[ TrackingProcessor ]: The collection " + std::string(Collections::TRACK_DATA) From ee771b653433a0086702d38020b00114f4e5fa05 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Mon, 16 Sep 2019 16:37:07 -0700 Subject: [PATCH 106/314] Refitted Track processor updates --- processors/include/RefittedTracksProcessor.h | 14 +- processors/src/RefittedTracksProcessor.cxx | 296 ++++++++++++------- 2 files changed, 200 insertions(+), 110 deletions(-) diff --git a/processors/include/RefittedTracksProcessor.h b/processors/include/RefittedTracksProcessor.h index 39ecfa189..f6ee7ead2 100644 --- a/processors/include/RefittedTracksProcessor.h +++ b/processors/include/RefittedTracksProcessor.h @@ -36,6 +36,9 @@ #include "Processor.h" #include "Track.h" #include "Event.h" +#include "TrackHistos.h" +#include "TrackerHit.h" +#include "RawSvtHit.h" // Forward declarations class TTree; @@ -82,9 +85,18 @@ class RefittedTracksProcessor : public Processor { /** Container to hold all Track objects. */ std::vector refit_tracks_{}; - bool _debug{false}; + /** Container to hold the hits on track */ + std::vector hits_{}; + /** Container to hold the raw hits */ + std::vector raw_hits_{}; + bool _debug{false}; + + TrackHistos* _OriginalTrkHistos; + TrackHistos* _RefitTrkHistos; + TrackHistos* _RefitTrkHistos_chi2cut; + TrackHistos* _RefitTrkHistos_z0cut; diff --git a/processors/src/RefittedTracksProcessor.cxx b/processors/src/RefittedTracksProcessor.cxx index ef1785952..908510d69 100644 --- a/processors/src/RefittedTracksProcessor.cxx +++ b/processors/src/RefittedTracksProcessor.cxx @@ -1,134 +1,92 @@ #include "RefittedTracksProcessor.h" #include +#include "utilities.h" + RefittedTracksProcessor::RefittedTracksProcessor(const std::string& name, Process& process) : Processor(name, process) { + + _OriginalTrkHistos = new TrackHistos("trk"); + _RefitTrkHistos = new TrackHistos("refit"); + _RefitTrkHistos_z0cut = new TrackHistos("refit_z0"); + _RefitTrkHistos_chi2cut = new TrackHistos("refit_chi2"); + + } RefittedTracksProcessor::~RefittedTracksProcessor() { } void RefittedTracksProcessor::initialize(TTree* tree) { - tree->Branch(Collections::GBL_TRACKS,&tracks_); - tree->Branch("GBLRefittedTracks", &refit_tracks_); + //tree->Branch("GBLRefittedTracks", &refit_tracks_); + + + //Original hists + _OriginalTrkHistos->doTrackComparisonPlots(false); + _OriginalTrkHistos->Define1DHistos(); + + //Refit hists + _RefitTrkHistos->doTrackComparisonPlots(true); + _RefitTrkHistos->Define1DHistos(); + _RefitTrkHistos->Define2DHistos(); + + //Refit hists with z0 closer to 0 + _RefitTrkHistos_z0cut->doTrackComparisonPlots(true); + _RefitTrkHistos_z0cut->Define1DHistos(); + _RefitTrkHistos_z0cut->Define2DHistos(); + + //Refit hists with z0 closer to 0 + _RefitTrkHistos_chi2cut->doTrackComparisonPlots(true); + _RefitTrkHistos_chi2cut->Define1DHistos(); + _RefitTrkHistos_chi2cut->Define2DHistos(); + + } bool RefittedTracksProcessor::process(IEvent* ievent) { + tracks_.clear(); + refit_tracks_.clear(); + Event* event = static_cast (ievent); - //Get all ethe tracks + //Get all the tracks EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); + + //Get all the 3D hits + EVENT::LCCollection* trackerHits = event->getLCCollection(Collections::TRACKER_HITS); + //Get all the rawHits fits + EVENT::LCCollection* raw_svt_hit_fits = event->getLCCollection(Collections::RAW_SVT_HIT_FITS); + + //Initialize map of shared hits + std::map > SharedHits; + //TODO: can we do better? (innermost) + std::map SharedHitsLy0; + std::map SharedHitsLy1; + + for (int itrack = 0; itrack < tracks->getNumberOfElements();++itrack) { + SharedHits[itrack] = {}; + SharedHitsLy0[itrack] = false; + SharedHitsLy1[itrack] = false; + } + // Loop over all the LCIO Tracks and add them to the HPS event. for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { // Get a LCIO Track from the LCIO event EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); - // Add a track to the event - Track* track = new Track(); - - // Set the track parameters - track->setTrackParameters(lc_track->getD0(), - lc_track->getPhi(), - lc_track->getOmega(), - lc_track->getTanLambda(), - lc_track->getZ0()); - - // Set the track type - track->setType(lc_track->getType()); - - // Set the track fit chi^2 - track->setChi2(lc_track->getChi2()); - - // Set the position of the extrapolated track at the ECal face. The - // extrapolation uses the full 3D field map. - const EVENT::TrackState* track_state - = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); - double position_at_ecal[3] = { - track_state->getReferencePoint()[1], - track_state->getReferencePoint()[2], - track_state->getReferencePoint()[0] - }; - track->setPositionAtEcal(position_at_ecal); - - // Get the collection of LCRelations between GBL kink data variables - // (GBLKinkData) and the corresponding track. + // Get the GBL kink data EVENT::LCCollection* gbl_kink_data = static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); - - // Instantiate an LCRelation navigator which will allow faster access - // to GBLKinkData object - UTIL::LCRelationNavigator* gbl_kink_data_nav - = new UTIL::LCRelationNavigator(gbl_kink_data); - - // Get the list of GBLKinkData associated with the LCIO Track - EVENT::LCObjectVec gbl_kink_data_list - = gbl_kink_data_nav->getRelatedFromObjects(lc_track); - - // The container of GBLKinkData objects should only contain a - // single object. If not, throw an exception - if (gbl_kink_data_list.size() != 1) { - throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA_REL) - + " has the wrong data structure."); - } - - // Get the list GBLKinkData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* gbl_kink_datum - = static_cast(gbl_kink_data_list.at(0)); - - // Set the lambda and phi kink values - for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { - track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); - track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); - } - - delete gbl_kink_data_nav; - - // Get the collection of LCRelations between track data variables - // (TrackData) and the corresponding track. - EVENT::LCCollection* track_data = static_cast( - event->getLCCollection(Collections::TRACK_DATA_REL)); - - // Instantiate an LCRelation navigator which will allow faster access - // to TrackData objects - UTIL::LCRelationNavigator* track_data_nav - = new UTIL::LCRelationNavigator(track_data); - - // Get the list of TrackData associated with the LCIO Track - EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); - - // The container of TrackData objects should only contain a single - // object. If not, throw an exception. - if (track_data_list.size() == 1) { - - // Get the TrackData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); - - // Check that the TrackData data structure is correct. If it's - // not, throw a runtime exception. - if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 - || track_datum->getNInt() != 1) { - throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA) - + " has the wrong structure."); - } - - // Set the SvtTrack isolation values - for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { - track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); - } - - // Set the SvtTrack time - track->setTrackTime(track_datum->getFloatVal(0)); - - // Set the volume (top/bottom) in which the SvtTrack resides - track->setTrackVolume(track_datum->getIntVal(0)); - } - delete track_data_nav; + // Get the track data + EVENT::LCCollection* track_data = static_cast(event->getLCCollection(Collections::TRACK_DATA_REL)); + + // Add a track to the event + Track* track = utils::buildTrack(lc_track, gbl_kink_data, track_data); + //Get the refitted tracks relations @@ -142,14 +100,128 @@ bool RefittedTracksProcessor::process(IEvent* ievent) { //Get the list of data EVENT::LCObjectVec refitted_tracks_list = refitted_tracks_nav -> getRelatedToObjects(lc_track); - std::cout<< std::fixed << std::setw( 11 ) << std::setprecision( 6 )<getD0()<<" " <getPhi()<<" "<getOmega()<<" "<getTanLambda()<<" "<getZ0()<(refitted_tracks_list.at(irtrk)); - std::cout<<"Refitted tracks params: "<getD0()<<" " << rfit_track->getPhi()<<" "<getOmega()<<" "<getTanLambda()<<" "<getZ0()<Print(); + + //Get the tracker hits + EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); + + + //Build the vector of Tracker Hits on track, get the info and attach them to the track. + for (int ith = 0; ith(lc_tracker_hits.at(ith)); + TrackerHit* th = utils::buildTrackerHit(lc_th); + //TODO should check the status of this return + utils::addRawInfoTo3dHit(th,lc_th,raw_svt_hit_fits); + //TODO this should be under some sort of saving flag + track->addHit(th); + hits_.push_back(th); + + //Get shared Hits information + for (int jtrack = itrack+1; jtrack < tracks->getNumberOfElements(); ++jtrack) { + + EVENT::Track* j_lc_track = static_cast(tracks->getElementAt(jtrack)); + if (utils::isUsedByTrack(th,j_lc_track)) { + //The hit is not already in the shared list + if (std::find(SharedHits[itrack].begin(), SharedHits[itrack].end(),th->getID()) == SharedHits[itrack].end()) { + SharedHits[itrack].push_back(th->getID()); + if (th->getLayer() == 0 ) + SharedHitsLy0[itrack] = true; + if (th->getLayer() == 1 ) + SharedHitsLy1[itrack] = true; + } + if (std::find(SharedHits[jtrack].begin(), SharedHits[jtrack].end(),th->getID()) == SharedHits[jtrack].end()) { + SharedHits[jtrack].push_back(th->getID()); + if (th->getLayer() == 0 ) + SharedHitsLy0[jtrack] = true; + if (th->getLayer() == 1 ) + SharedHitsLy1[jtrack] = true; + } + } // found shared hit + } // loop on j>i tracks + } // loop on hits on track i + + //TODO:: bug prone? + track->setNShared(SharedHits[itrack].size()); + track->setSharedLy0(SharedHitsLy0[itrack]); + track->setSharedLy1(SharedHitsLy1[itrack]); + + //std::cout<<"Tracker hits time:"; + //for (auto lc_tracker_hit : lc_tracker_hits) { + //std::cout<<" "<getTime(); + //} + //std::cout<(refitted_tracks_list.at(irtrk)); + if (irtrk == 0) { + bestX2 = (lc_rfit_track->getChi2() / lc_rfit_track->getNdf()); + bestX2index = 0; + } + else + if ((lc_rfit_track->getChi2() / lc_rfit_track->getNdf()) < bestX2) { + bestX2 = (lc_rfit_track->getChi2() / lc_rfit_track->getNdf()); + bestX2index = irtrk; + } } + + _OriginalTrkHistos->Fill1DHistograms(track); + for (int irtrk = 0; irtrk < refitted_tracks_list.size(); irtrk++) { + + if (irtrk != bestX2index) + continue; + + EVENT::Track* lc_rfit_track = static_cast(refitted_tracks_list.at(irtrk)); + + //Useless to get it every track + // Get the GBL kink data + EVENT::LCCollection* rfit_gbl_kink_data = + static_cast(event->getLCCollection("GBLKinkDataRelations_refit")); + // Get the track data + EVENT::LCCollection* rfit_track_data = nullptr; + Track* rfit_track = utils::buildTrack(lc_rfit_track,rfit_gbl_kink_data,rfit_track_data); + EVENT::TrackerHitVec lc_rf_tracker_hits = lc_rfit_track->getTrackerHits(); + + //TODO::move to utilities + //recompute time if missing information + float mean = 0.0; + for (auto lc_rf_tracker_hit : lc_rf_tracker_hits) { + mean += lc_rf_tracker_hit->getTime(); + } + rfit_track->setTrackTime(mean / lc_rf_tracker_hits.size()); + + //std::cout<<"Refitted tracks params: "<Print(); + + //std::cout<<"Tracker hits time:"; + //for (auto lc_rf_tracker_hit : lc_rf_tracker_hits) { + //std::cout<<" "<getTime(); + //} + //std::cout<Fill1DHistograms(rfit_track); + _RefitTrkHistos->FillTrackComparisonHistograms(track,rfit_track); + + if (fabs(rfit_track->getZ0()) < fabs(track->getZ0())) { + _RefitTrkHistos_z0cut->Fill1DHistograms(rfit_track); + _RefitTrkHistos_z0cut->FillTrackComparisonHistograms(track,rfit_track); + } + + if (rfit_track->getChi2Ndf() < track->getChi2Ndf()) { + _RefitTrkHistos_chi2cut->Fill1DHistograms(rfit_track); + _RefitTrkHistos_chi2cut->FillTrackComparisonHistograms(track,rfit_track); + } + }//loop on refit tracks }//Loop on tracks @@ -158,6 +230,12 @@ bool RefittedTracksProcessor::process(IEvent* ievent) { } void RefittedTracksProcessor::finalize() { + + _OriginalTrkHistos ->saveHistos(); + _RefitTrkHistos ->saveHistos(); + _RefitTrkHistos_z0cut ->saveHistos(); + _RefitTrkHistos_chi2cut ->saveHistos(); + } DECLARE_PROCESSOR(RefittedTracksProcessor); From a31b211697014f97ba146ab19fe0bd7e28ad27df Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 17 Sep 2019 11:22:47 -0700 Subject: [PATCH 107/314] Module Mapper class --- analysis/include/ModuleMapper.h | 35 +++++ analysis/src/ModuleMapper.cxx | 259 ++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 analysis/include/ModuleMapper.h create mode 100644 analysis/src/ModuleMapper.cxx diff --git a/analysis/include/ModuleMapper.h b/analysis/include/ModuleMapper.h new file mode 100644 index 000000000..8a07cf779 --- /dev/null +++ b/analysis/include/ModuleMapper.h @@ -0,0 +1,35 @@ +#ifndef _MODULE_MAPPER_H_ +#define _MODULE_MAPPER_H_ +#include +#include + + +class ModuleMapper { + + public: + ModuleMapper(); + ModuleMapper(const int year) {year_ = year;}; + + //TODO, clean up? + ~ModuleMapper(); + + + //Bidirectional maps could be used + + private: + + int year_{2019}; + + std::map hw_to_sw; + std::map sw_to_hw; + + std::map hw_to_string; + std::map string_to_hw; + + std::map sw_to_string; + std::map string_to_sw; + + +}; + +#endif //_MODULE_MAPPER_H_ diff --git a/analysis/src/ModuleMapper.cxx b/analysis/src/ModuleMapper.cxx new file mode 100644 index 000000000..55e0857ca --- /dev/null +++ b/analysis/src/ModuleMapper.cxx @@ -0,0 +1,259 @@ +#include "ModuleMapper.h" + +ModuleMapper::ModuleMapper() { + + hw_to_sw["F0H0"] = "ly1_m0"; + hw_to_sw["F0H1"] = "ly2_m0"; + hw_to_sw["F0H2"] = "ly3_m0"; + hw_to_sw["F0H3"] = "ly4_m0"; + hw_to_sw["F1H0"] = "ly4_m1"; + hw_to_sw["F1H1"] = "ly3_m1"; + hw_to_sw["F1H2"] = "ly2_m1"; + hw_to_sw["F1H3"] = "ly1_m1"; + hw_to_sw["F2H0"] = "ly5_m0"; + hw_to_sw["F2H1"] = "ly6_m0"; + hw_to_sw["F2H2"] = "ly8_m0"; + hw_to_sw["F2H3"] = "ly7_m0"; + hw_to_sw["F3H0"] = "ly7_m1"; + hw_to_sw["F3H1"] = "ly8_m1"; + hw_to_sw["F3H2"] = "ly5_m1"; + hw_to_sw["F3H3"] = "ly6_m1"; + hw_to_sw["F4H0"] = "ly9_m0"; + hw_to_sw["F4H1"] = "ly9_m2"; + hw_to_sw["F4H2"] = "ly10_m0"; + hw_to_sw["F4H3"] = "ly10_m2"; + hw_to_sw["F5H0"] = "ly9_m1"; + hw_to_sw["F5H1"] = "ly9_m3"; + hw_to_sw["F5H2"] = "ly10_m1"; + hw_to_sw["F5H3"] = "ly10_m3"; + hw_to_sw["F6H0"] = "ly11_m0"; + hw_to_sw["F6H1"] = "ly11_m2"; + hw_to_sw["F6H2"] = "ly12_m0"; + hw_to_sw["F6H3"] = "ly12_m2"; + hw_to_sw["F7H0"] = "ly11_m1"; + hw_to_sw["F7H1"] = "ly11_m3"; + hw_to_sw["F7H2"] = "ly12_m1"; + hw_to_sw["F7H3"] = "ly12_m3"; + hw_to_sw["F8H0"] = "ly13_m0"; + hw_to_sw["F8H1"] = "ly13_m2"; + hw_to_sw["F8H2"] = "ly14_m0"; + hw_to_sw["F8H3"] = "ly14_m2"; + hw_to_sw["F9H0"] = "ly13_m1"; + hw_to_sw["F9H1"] = "ly13_m3"; + hw_to_sw["F9H2"] = "ly14_m1"; + hw_to_sw["F9H3"] = "ly14_m3"; + + sw_to_hw["ly1_m0"] = "F0H0" ; + sw_to_hw["ly2_m0"] = "F0H1" ; + sw_to_hw["ly3_m0"] = "F0H2" ; + sw_to_hw["ly4_m0"] = "F0H3" ; + sw_to_hw["ly4_m1"] = "F1H0" ; + sw_to_hw["ly3_m1"] = "F1H1" ; + sw_to_hw["ly2_m1"] = "F1H2" ; + sw_to_hw["ly1_m1"] = "F1H3" ; + sw_to_hw["ly5_m0"] = "F2H0" ; + sw_to_hw["ly6_m0"] = "F2H1" ; + sw_to_hw["ly8_m0"] = "F2H2" ; + sw_to_hw["ly7_m0"] = "F2H3" ; + sw_to_hw["ly7_m1"] = "F3H0" ; + sw_to_hw["ly8_m1"] = "F3H1" ; + sw_to_hw["ly5_m1"] = "F3H2" ; + sw_to_hw["ly6_m1"] = "F3H3" ; + sw_to_hw["ly9_m0"] = "F4H0" ; + sw_to_hw["ly9_m2"] = "F4H1" ; + sw_to_hw["ly10_m0"] = "F4H2"; + sw_to_hw["ly10_m2"] = "F4H3"; + sw_to_hw["ly9_m1"] = "F5H0" ; + sw_to_hw["ly9_m3"] = "F5H1" ; + sw_to_hw["ly10_m1"] = "F5H2"; + sw_to_hw["ly10_m3"] = "F5H3"; + sw_to_hw["ly11_m0"] = "F6H0"; + sw_to_hw["ly11_m2"] = "F6H1"; + sw_to_hw["ly12_m0"] = "F6H2"; + sw_to_hw["ly12_m2"] = "F6H3"; + sw_to_hw["ly11_m1"] = "F7H0"; + sw_to_hw["ly11_m3"] = "F7H1"; + sw_to_hw["ly12_m1"] = "F7H2"; + sw_to_hw["ly12_m3"] = "F7H3"; + sw_to_hw["ly13_m0"] = "F8H0"; + sw_to_hw["ly13_m2"] = "F8H1"; + sw_to_hw["ly14_m0"] = "F8H2"; + sw_to_hw["ly14_m2"] = "F8H3"; + sw_to_hw["ly13_m1"] = "F9H0"; + sw_to_hw["ly13_m3"] = "F9H1"; + sw_to_hw["ly14_m1"] = "F9H2"; + sw_to_hw["ly14_m3"] = "F9H3"; + + // HW to string and viceversa + + hw_to_string["F0H0"] = ""; + hw_to_string["F0H1"] = ""; + hw_to_string["F0H2"] = ""; + hw_to_string["F0H3"] = ""; + hw_to_string["F1H0"] = ""; + hw_to_string["F1H1"] = ""; + hw_to_string["F1H2"] = ""; + hw_to_string["F1H3"] = ""; + hw_to_string["F2H0"] = ""; + hw_to_string["F2H1"] = ""; + hw_to_string["F2H2"] = ""; + hw_to_string["F2H3"] = ""; + hw_to_string["F3H0"] = ""; + hw_to_string["F3H1"] = ""; + hw_to_string["F3H2"] = ""; + hw_to_string["F3H3"] = ""; + hw_to_string["F4H0"] = ""; + hw_to_string["F4H1"] = ""; + hw_to_string["F4H2"] = ""; + hw_to_string["F4H3"] = ""; + hw_to_string["F5H0"] = ""; + hw_to_string["F5H1"] = ""; + hw_to_string["F5H2"] = ""; + hw_to_string["F5H3"] = ""; + hw_to_string["F6H0"] = ""; + hw_to_string["F6H1"] = ""; + hw_to_string["F6H2"] = ""; + hw_to_string["F6H3"] = ""; + hw_to_string["F7H0"] = ""; + hw_to_string["F7H1"] = ""; + hw_to_string["F7H2"] = ""; + hw_to_string["F7H3"] = ""; + hw_to_string["F8H0"] = ""; + hw_to_string["F8H1"] = ""; + hw_to_string["F8H2"] = ""; + hw_to_string["F8H3"] = ""; + hw_to_string["F9H0"] = ""; + hw_to_string["F9H1"] = ""; + hw_to_string["F9H2"] = ""; + hw_to_string["F9H3"] = ""; + + string_to_hw[] = "F0H0"; + string_to_hw[] = "F0H1"; + string_to_hw[] = "F0H2"; + string_to_hw[] = "F0H3"; + string_to_hw[] = "F1H0"; + string_to_hw[] = "F1H1"; + string_to_hw[] = "F1H2"; + string_to_hw[] = "F1H3"; + string_to_hw[] = "F2H0"; + string_to_hw[] = "F2H1"; + string_to_hw[] = "F2H2"; + string_to_hw[] = "F2H3"; + string_to_hw[] = "F3H0"; + string_to_hw[] = "F3H1"; + string_to_hw[] = "F3H2"; + string_to_hw[] = "F3H3"; + string_to_hw[] = "F4H0"; + string_to_hw[] = "F4H1"; + string_to_hw[] = "F4H2"; + string_to_hw[] = "F4H3"; + string_to_hw[] = "F5H0"; + string_to_hw[] = "F5H1"; + string_to_hw[] = "F5H2"; + string_to_hw[] = "F5H3"; + string_to_hw[] = "F6H0"; + string_to_hw[] = "F6H1"; + string_to_hw[] = "F6H2"; + string_to_hw[] = "F6H3"; + string_to_hw[] = "F7H0"; + string_to_hw[] = "F7H1"; + string_to_hw[] = "F7H2"; + string_to_hw[] = "F7H3"; + string_to_hw[] = "F8H0"; + string_to_hw[] = "F8H1"; + string_to_hw[] = "F8H2"; + string_to_hw[] = "F8H3"; + string_to_hw[] = "F9H0"; + string_to_hw[] = "F9H1"; + string_to_hw[] = "F9H2"; + string_to_hw[] = "F9H3"; + + + //sw to string + //string format : ___ + + sw_to_string["ly1_m0"] = "" ; + sw_to_string["ly2_m0"] = "" ; + sw_to_string["ly3_m0"] = "" ; + sw_to_string["ly4_m0"] = "" ; + sw_to_string["ly4_m1"] = "" ; + sw_to_string["ly3_m1"] = "" ; + sw_to_string["ly2_m1"] = "" ; + sw_to_string["ly1_m1"] = "" ; + sw_to_string["ly5_m0"] = "" ; + sw_to_string["ly6_m0"] = "" ; + sw_to_string["ly8_m0"] = "" ; + sw_to_string["ly7_m0"] = "" ; + sw_to_string["ly7_m1"] = "" ; + sw_to_string["ly8_m1"] = "" ; + sw_to_string["ly5_m1"] = "" ; + sw_to_string["ly6_m1"] = "" ; + sw_to_string["ly9_m0"] = "" ; + sw_to_string["ly9_m2"] = "" ; + sw_to_string["ly10_m0"] = "" ; + sw_to_string["ly10_m2"] = "" ; + sw_to_string["ly9_m1"] = "" ; + sw_to_string["ly9_m3"] = "" ; + sw_to_string["ly10_m1"] = "" ; + sw_to_string["ly10_m3"] = "" ; + sw_to_string["ly11_m0"] = "" ; + sw_to_string["ly11_m2"] = "" ; + sw_to_string["ly12_m0"] = "" ; + sw_to_string["ly12_m2"] = "" ; + sw_to_string["ly11_m1"] = "" ; + sw_to_string["ly11_m3"] = "" ; + sw_to_string["ly12_m1"] = "" ; + sw_to_string["ly12_m3"] = "" ; + sw_to_string["ly13_m0"] = "" ; + sw_to_string["ly13_m2"] = "" ; + sw_to_string["ly14_m0"] = "" ; + sw_to_string["ly14_m2"] = "" ; + sw_to_string["ly13_m1"] = "" ; + sw_to_string["ly13_m3"] = "" ; + sw_to_string["ly14_m1"] = "" ; + sw_to_string["ly14_m3"] = "" ; + + + sw_to_string[""] = "ly1_m0" ; + sw_to_string[""] = "ly2_m0" ; + sw_to_string[""] = "ly3_m0" ; + sw_to_string[""] = "ly4_m0" ; + sw_to_string[""] = "ly4_m1" ; + sw_to_string[""] = "ly3_m1" ; + sw_to_string[""] = "ly2_m1" ; + sw_to_string[""] = "ly1_m1" ; + sw_to_string[""] = "ly5_m0" ; + sw_to_string[""] = "ly6_m0" ; + sw_to_string[""] = "ly8_m0" ; + sw_to_string[""] = "ly7_m0" ; + sw_to_string[""] = "ly7_m1" ; + sw_to_string[""] = "ly8_m1" ; + sw_to_string[""] = "ly5_m1" ; + sw_to_string[""] = "ly6_m1" ; + sw_to_string[""] = "ly9_m0" ; + sw_to_string[""] = "ly9_m2" ; + sw_to_string[""] = "ly10_m0" ; + sw_to_string[""] = "ly10_m2" ; + sw_to_string[""] = "ly9_m1" ; + sw_to_string[""] = "ly9_m3" ; + sw_to_string[""] = "ly10_m1" ; + sw_to_string[""] = "ly10_m3" ; + sw_to_string[""] = "ly11_m0" ; + sw_to_string[""] = "ly11_m2" ; + sw_to_string[""] = "ly12_m0" ; + sw_to_string[""] = "ly12_m2" ; + sw_to_string[""] = "ly11_m1" ; + sw_to_string[""] = "ly11_m3" ; + sw_to_string[""] = "ly12_m1" ; + sw_to_string[""] = "ly12_m3" ; + sw_to_string[""] = "ly13_m0" ; + sw_to_string[""] = "ly13_m2" ; + sw_to_string[""] = "ly14_m0" ; + sw_to_string[""] = "ly14_m2" ; + sw_to_string[""] = "ly13_m1" ; + sw_to_string[""] = "ly13_m3" ; + sw_to_string[""] = "ly14_m1" ; + sw_to_string[""] = "ly14_m3" ; + +} //constructor + From 914fad9333851bf828d1e9827b41f145176ae9d4 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 17 Sep 2019 11:53:00 -0700 Subject: [PATCH 108/314] removed deprecated runAnalysis --- analysis/src/runAnalysis.cxx | 42 ------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 analysis/src/runAnalysis.cxx diff --git a/analysis/src/runAnalysis.cxx b/analysis/src/runAnalysis.cxx deleted file mode 100644 index e3fe7a7b7..000000000 --- a/analysis/src/runAnalysis.cxx +++ /dev/null @@ -1,42 +0,0 @@ - -#include "EventHeader.h" //CONTAINS LCIO. I don't want that! -#include "Track.h" -#include "TFile.h" -#include "TTree.h" - -#include "TBranch.h" - -#include - -int main(int argc, char** argv) { - - - TFile* inputFile = new TFile("/Users/Pierfrancesco/HPS/sw/hipster/run/testRun.root"); - TTree* t = (TTree*) inputFile->Get("HPS_Event"); - long nentries = t->GetEntriesFast(); - std::cout<<"n entries "<SetBranchAddress("GBLTracks",&tracks,&btracks); - - for (int ientry=0; ientry<100;ientry++) { - t->GetEntry(ientry); - std::cout<<"Number of Tracks in the event:"<GetEntries()<GetEntries();itrack++) { - Track *track = (Track*)tracks->ConstructedAt(itrack); - - std::cout<<"Tracks number of hits for track "<getNSvtHits()< Date: Tue, 17 Sep 2019 11:54:44 -0700 Subject: [PATCH 109/314] Removed runAnalysis from Cmake list --- analysis/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/analysis/CMakeLists.txt b/analysis/CMakeLists.txt index 1cb8e5643..35f83a209 100644 --- a/analysis/CMakeLists.txt +++ b/analysis/CMakeLists.txt @@ -2,7 +2,6 @@ # Declare analysis module module( NAME analysis - EXECUTABLES ./src/runAnalysis.cxx DEPENDENCIES event EXTERNAL_DEPENDENCIES ROOT ) From da5e0ebba34aab48ba5dfe66410a4676a768634f Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 17 Sep 2019 12:00:06 -0700 Subject: [PATCH 110/314] remove --- event/include/Event.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event/include/Event.h b/event/include/Event.h index 724854c4c..9a85130a9 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -12,7 +12,7 @@ // C++ StdLib // //----------------// #include -#include + //----------// // LCIO // From 332fea27648db29ea4c1852be1c9c5e86ffb0f24 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 17 Sep 2019 13:27:50 -0700 Subject: [PATCH 111/314] Add strings to module map class --- analysis/src/ModuleMapper.cxx | 321 +++++++++++++++++----------------- 1 file changed, 161 insertions(+), 160 deletions(-) diff --git a/analysis/src/ModuleMapper.cxx b/analysis/src/ModuleMapper.cxx index 55e0857ca..d7d6ce636 100644 --- a/analysis/src/ModuleMapper.cxx +++ b/analysis/src/ModuleMapper.cxx @@ -85,175 +85,176 @@ ModuleMapper::ModuleMapper() { sw_to_hw["ly14_m3"] = "F9H3"; // HW to string and viceversa + //string format : ___ - hw_to_string["F0H0"] = ""; - hw_to_string["F0H1"] = ""; - hw_to_string["F0H2"] = ""; - hw_to_string["F0H3"] = ""; - hw_to_string["F1H0"] = ""; - hw_to_string["F1H1"] = ""; - hw_to_string["F1H2"] = ""; - hw_to_string["F1H3"] = ""; - hw_to_string["F2H0"] = ""; - hw_to_string["F2H1"] = ""; - hw_to_string["F2H2"] = ""; - hw_to_string["F2H3"] = ""; - hw_to_string["F3H0"] = ""; - hw_to_string["F3H1"] = ""; - hw_to_string["F3H2"] = ""; - hw_to_string["F3H3"] = ""; - hw_to_string["F4H0"] = ""; - hw_to_string["F4H1"] = ""; - hw_to_string["F4H2"] = ""; - hw_to_string["F4H3"] = ""; - hw_to_string["F5H0"] = ""; - hw_to_string["F5H1"] = ""; - hw_to_string["F5H2"] = ""; - hw_to_string["F5H3"] = ""; - hw_to_string["F6H0"] = ""; - hw_to_string["F6H1"] = ""; - hw_to_string["F6H2"] = ""; - hw_to_string["F6H3"] = ""; - hw_to_string["F7H0"] = ""; - hw_to_string["F7H1"] = ""; - hw_to_string["F7H2"] = ""; - hw_to_string["F7H3"] = ""; - hw_to_string["F8H0"] = ""; - hw_to_string["F8H1"] = ""; - hw_to_string["F8H2"] = ""; - hw_to_string["F8H3"] = ""; - hw_to_string["F9H0"] = ""; - hw_to_string["F9H1"] = ""; - hw_to_string["F9H2"] = ""; - hw_to_string["F9H3"] = ""; + hw_to_string["F0H0"] = "L0T_axial"; + hw_to_string["F0H1"] = "L0T_stereo"; + hw_to_string["F0H2"] = "L1T_axial"; + hw_to_string["F0H3"] = "L1T_stereo"; + hw_to_string["F1H0"] = "L1B_axial"; + hw_to_string["F1H1"] = "L1B_stereo"; + hw_to_string["F1H2"] = "L0B_axial"; + hw_to_string["F1H3"] = "L0B_stereo"; + hw_to_string["F2H0"] = "L2T_axial"; + hw_to_string["F2H1"] = "L2T_stereo"; + hw_to_string["F2H2"] = "L3T_axial"; + hw_to_string["F2H3"] = "L3T_stereo"; + hw_to_string["F3H0"] = "L3B_axial"; + hw_to_string["F3H1"] = "L3B_stereo"; + hw_to_string["F3H2"] = "L2B_axial"; + hw_to_string["F3H3"] = "L2B_stereo"; + hw_to_string["F4H0"] = "L4T_axial_ele"; + hw_to_string["F4H1"] = "L4T_axial_pos"; + hw_to_string["F4H2"] = "L4T_stereo_ele"; + hw_to_string["F4H3"] = "L4T_stereo_pos"; + hw_to_string["F5H0"] = "L4B_stereo_ele"; + hw_to_string["F5H1"] = "L4B_stereo_pos"; + hw_to_string["F5H2"] = "L4B_axial_ele"; + hw_to_string["F5H3"] = "L4B_axial_pos"; + hw_to_string["F6H0"] = "L5T_axial_ele"; + hw_to_string["F6H1"] = "L5T_axial_pos"; + hw_to_string["F6H2"] = "L5T_stereo_ele"; + hw_to_string["F6H3"] = "L5T_stereo_pos"; + hw_to_string["F7H0"] = "L5B_stereo_ele"; + hw_to_string["F7H1"] = "L5B_stereo_pos"; + hw_to_string["F7H2"] = "L5B_axial_ele"; + hw_to_string["F7H3"] = "L5B_axial_pos"; + hw_to_string["F8H0"] = "L6T_axial_ele"; + hw_to_string["F8H1"] = "L6T_axial_pos"; + hw_to_string["F8H2"] = "L6T_stereo_ele"; + hw_to_string["F8H3"] = "L6T_stereo_pos"; + hw_to_string["F9H0"] = "L6B_stereo_ele"; + hw_to_string["F9H1"] = "L6B_stereo_pos"; + hw_to_string["F9H2"] = "L6B_axial_ele"; + hw_to_string["F9H3"] = "L6B_axial_pos"; - string_to_hw[] = "F0H0"; - string_to_hw[] = "F0H1"; - string_to_hw[] = "F0H2"; - string_to_hw[] = "F0H3"; - string_to_hw[] = "F1H0"; - string_to_hw[] = "F1H1"; - string_to_hw[] = "F1H2"; - string_to_hw[] = "F1H3"; - string_to_hw[] = "F2H0"; - string_to_hw[] = "F2H1"; - string_to_hw[] = "F2H2"; - string_to_hw[] = "F2H3"; - string_to_hw[] = "F3H0"; - string_to_hw[] = "F3H1"; - string_to_hw[] = "F3H2"; - string_to_hw[] = "F3H3"; - string_to_hw[] = "F4H0"; - string_to_hw[] = "F4H1"; - string_to_hw[] = "F4H2"; - string_to_hw[] = "F4H3"; - string_to_hw[] = "F5H0"; - string_to_hw[] = "F5H1"; - string_to_hw[] = "F5H2"; - string_to_hw[] = "F5H3"; - string_to_hw[] = "F6H0"; - string_to_hw[] = "F6H1"; - string_to_hw[] = "F6H2"; - string_to_hw[] = "F6H3"; - string_to_hw[] = "F7H0"; - string_to_hw[] = "F7H1"; - string_to_hw[] = "F7H2"; - string_to_hw[] = "F7H3"; - string_to_hw[] = "F8H0"; - string_to_hw[] = "F8H1"; - string_to_hw[] = "F8H2"; - string_to_hw[] = "F8H3"; - string_to_hw[] = "F9H0"; - string_to_hw[] = "F9H1"; - string_to_hw[] = "F9H2"; - string_to_hw[] = "F9H3"; + string_to_hw["L0T_axial"] = "F0H0"; + string_to_hw["L0T_stereo"] = "F0H1"; + string_to_hw["L1T_axial"] = "F0H2"; + string_to_hw["L1T_stereo"] = "F0H3"; + string_to_hw["L1B_axial"] = "F1H0"; + string_to_hw["L1B_stereo"] = "F1H1"; + string_to_hw["L0B_axial"] = "F1H2"; + string_to_hw["L0B_stereo"] = "F1H3"; + string_to_hw["L2T_axial"] = "F2H0"; + string_to_hw["L2T_stereo"] = "F2H1"; + string_to_hw["L3T_axial"] = "F2H2"; + string_to_hw["L3T_stereo"] = "F2H3"; + string_to_hw["L3B_axial"] = "F3H0"; + string_to_hw["L3B_stereo"] = "F3H1"; + string_to_hw["L2B_axial"] = "F3H2"; + string_to_hw["L2B_stereo"] = "F3H3"; + string_to_hw["L4T_axial_ele"] = "F4H0"; + string_to_hw["L4T_axial_pos"] = "F4H1"; + string_to_hw["L4T_stereo_ele"] = "F4H2"; + string_to_hw["L4T_stereo_pos"] = "F4H3"; + string_to_hw["L4B_stereo_ele"] = "F5H0"; + string_to_hw["L4B_stereo_pos"] = "F5H1"; + string_to_hw["L4B_axial_ele"] = "F5H2"; + string_to_hw["L4B_axial_pos"] = "F5H3"; + string_to_hw["L5T_axial_ele"] = "F6H0"; + string_to_hw["L5T_axial_pos"] = "F6H1"; + string_to_hw["L5T_stereo_ele"] = "F6H2"; + string_to_hw["L5T_stereo_pos"] = "F6H3"; + string_to_hw["L5B_stereo_ele"] = "F7H0"; + string_to_hw["L5B_stereo_pos"] = "F7H1"; + string_to_hw["L5B_axial_ele"] = "F7H2"; + string_to_hw["L5B_axial_pos"] = "F7H3"; + string_to_hw["L6T_axial_ele"] = "F8H0"; + string_to_hw["L6T_axial_pos"] = "F8H1"; + string_to_hw["L6T_stereo_ele"] = "F8H2"; + string_to_hw["L6T_stereo_pos"] = "F8H3"; + string_to_hw["L6B_stereo_ele"] = "F9H0"; + string_to_hw["L6B_stereo_pos"] = "F9H1"; + string_to_hw["L6B_axial_ele"] = "F9H2"; + string_to_hw["L6B_axial_pos"] = "F9H3"; //sw to string //string format : ___ - sw_to_string["ly1_m0"] = "" ; - sw_to_string["ly2_m0"] = "" ; - sw_to_string["ly3_m0"] = "" ; - sw_to_string["ly4_m0"] = "" ; - sw_to_string["ly4_m1"] = "" ; - sw_to_string["ly3_m1"] = "" ; - sw_to_string["ly2_m1"] = "" ; - sw_to_string["ly1_m1"] = "" ; - sw_to_string["ly5_m0"] = "" ; - sw_to_string["ly6_m0"] = "" ; - sw_to_string["ly8_m0"] = "" ; - sw_to_string["ly7_m0"] = "" ; - sw_to_string["ly7_m1"] = "" ; - sw_to_string["ly8_m1"] = "" ; - sw_to_string["ly5_m1"] = "" ; - sw_to_string["ly6_m1"] = "" ; - sw_to_string["ly9_m0"] = "" ; - sw_to_string["ly9_m2"] = "" ; - sw_to_string["ly10_m0"] = "" ; - sw_to_string["ly10_m2"] = "" ; - sw_to_string["ly9_m1"] = "" ; - sw_to_string["ly9_m3"] = "" ; - sw_to_string["ly10_m1"] = "" ; - sw_to_string["ly10_m3"] = "" ; - sw_to_string["ly11_m0"] = "" ; - sw_to_string["ly11_m2"] = "" ; - sw_to_string["ly12_m0"] = "" ; - sw_to_string["ly12_m2"] = "" ; - sw_to_string["ly11_m1"] = "" ; - sw_to_string["ly11_m3"] = "" ; - sw_to_string["ly12_m1"] = "" ; - sw_to_string["ly12_m3"] = "" ; - sw_to_string["ly13_m0"] = "" ; - sw_to_string["ly13_m2"] = "" ; - sw_to_string["ly14_m0"] = "" ; - sw_to_string["ly14_m2"] = "" ; - sw_to_string["ly13_m1"] = "" ; - sw_to_string["ly13_m3"] = "" ; - sw_to_string["ly14_m1"] = "" ; - sw_to_string["ly14_m3"] = "" ; + sw_to_string["ly1_m0"] = "L0T_axial"; + sw_to_string["ly2_m0"] = "L0T_stereo"; + sw_to_string["ly3_m0"] = "L1T_axial"; + sw_to_string["ly4_m0"] = "L1T_stereo"; + sw_to_string["ly4_m1"] = "L1B_axial"; + sw_to_string["ly3_m1"] = "L1B_stereo"; + sw_to_string["ly2_m1"] = "L0B_axial"; + sw_to_string["ly1_m1"] = "L0B_stereo"; + sw_to_string["ly5_m0"] = "L2T_axial"; + sw_to_string["ly6_m0"] = "L2T_stereo"; + sw_to_string["ly8_m0"] = "L3T_axial"; + sw_to_string["ly7_m0"] = "L3T_stereo"; + sw_to_string["ly7_m1"] = "L3B_axial"; + sw_to_string["ly8_m1"] = "L3B_stereo"; + sw_to_string["ly5_m1"] = "L2B_axial"; + sw_to_string["ly6_m1"] = "L2B_stereo"; + sw_to_string["ly9_m0"] = "L4T_axial_ele"; + sw_to_string["ly9_m2"] = "L4T_axial_pos"; + sw_to_string["ly10_m0"] = "L4T_stereo_ele"; + sw_to_string["ly10_m2"] = "L4T_stereo_pos"; + sw_to_string["ly9_m1"] = "L4B_stereo_ele"; + sw_to_string["ly9_m3"] = "L4B_stereo_pos"; + sw_to_string["ly10_m1"] = "L4B_axial_ele"; + sw_to_string["ly10_m3"] = "L4B_axial_pos"; + sw_to_string["ly11_m0"] = "L5T_axial_ele"; + sw_to_string["ly11_m2"] = "L5T_axial_pos"; + sw_to_string["ly12_m0"] = "L5T_stereo_ele"; + sw_to_string["ly12_m2"] = "L5T_stereo_pos"; + sw_to_string["ly11_m1"] = "L5B_stereo_ele"; + sw_to_string["ly11_m3"] = "L5B_stereo_pos"; + sw_to_string["ly12_m1"] = "L5B_axial_ele"; + sw_to_string["ly12_m3"] = "L5B_axial_pos"; + sw_to_string["ly13_m0"] = "L6T_axial_ele"; + sw_to_string["ly13_m2"] = "L6T_axial_pos"; + sw_to_string["ly14_m0"] = "L6T_stereo_ele"; + sw_to_string["ly14_m2"] = "L6T_stereo_pos"; + sw_to_string["ly13_m1"] = "L6B_stereo_ele"; + sw_to_string["ly13_m3"] = "L6B_stereo_pos"; + sw_to_string["ly14_m1"] = "L6B_axial_ele"; + sw_to_string["ly14_m3"] = "L6B_axial_pos"; - sw_to_string[""] = "ly1_m0" ; - sw_to_string[""] = "ly2_m0" ; - sw_to_string[""] = "ly3_m0" ; - sw_to_string[""] = "ly4_m0" ; - sw_to_string[""] = "ly4_m1" ; - sw_to_string[""] = "ly3_m1" ; - sw_to_string[""] = "ly2_m1" ; - sw_to_string[""] = "ly1_m1" ; - sw_to_string[""] = "ly5_m0" ; - sw_to_string[""] = "ly6_m0" ; - sw_to_string[""] = "ly8_m0" ; - sw_to_string[""] = "ly7_m0" ; - sw_to_string[""] = "ly7_m1" ; - sw_to_string[""] = "ly8_m1" ; - sw_to_string[""] = "ly5_m1" ; - sw_to_string[""] = "ly6_m1" ; - sw_to_string[""] = "ly9_m0" ; - sw_to_string[""] = "ly9_m2" ; - sw_to_string[""] = "ly10_m0" ; - sw_to_string[""] = "ly10_m2" ; - sw_to_string[""] = "ly9_m1" ; - sw_to_string[""] = "ly9_m3" ; - sw_to_string[""] = "ly10_m1" ; - sw_to_string[""] = "ly10_m3" ; - sw_to_string[""] = "ly11_m0" ; - sw_to_string[""] = "ly11_m2" ; - sw_to_string[""] = "ly12_m0" ; - sw_to_string[""] = "ly12_m2" ; - sw_to_string[""] = "ly11_m1" ; - sw_to_string[""] = "ly11_m3" ; - sw_to_string[""] = "ly12_m1" ; - sw_to_string[""] = "ly12_m3" ; - sw_to_string[""] = "ly13_m0" ; - sw_to_string[""] = "ly13_m2" ; - sw_to_string[""] = "ly14_m0" ; - sw_to_string[""] = "ly14_m2" ; - sw_to_string[""] = "ly13_m1" ; - sw_to_string[""] = "ly13_m3" ; - sw_to_string[""] = "ly14_m1" ; - sw_to_string[""] = "ly14_m3" ; + string_to_sw["L0T_axial"] = "ly1_m0" ; + string_to_sw["L0T_stereo"] = "ly2_m0" ; + string_to_sw["L1T_axial"] = "ly3_m0" ; + string_to_sw["L1T_stereo"] = "ly4_m0" ; + string_to_sw["L1B_axial"] = "ly4_m1" ; + string_to_sw["L1B_stereo"] = "ly3_m1" ; + string_to_sw["L0B_axial"] = "ly2_m1" ; + string_to_sw["L0B_stereo"] = "ly1_m1" ; + string_to_sw["L2T_axial"] = "ly5_m0" ; + string_to_sw["L2T_stereo"] = "ly6_m0" ; + string_to_sw["L3T_axial"] = "ly8_m0" ; + string_to_sw["L3T_stereo"] = "ly7_m0" ; + string_to_sw["L3B_axial"] = "ly7_m1" ; + string_to_sw["L3B_stereo"] = "ly8_m1" ; + string_to_sw["L2B_axial"] = "ly5_m1" ; + string_to_sw["L2B_stereo"] = "ly6_m1" ; + string_to_sw["L4T_axial_ele"] = "ly9_m0" ; + string_to_sw["L4T_axial_pos"] = "ly9_m2" ; + string_to_sw["L4T_stereo_ele"] = "ly10_m0" ; + string_to_sw["L4T_stereo_pos"] = "ly10_m2" ; + string_to_sw["L4B_stereo_ele"] = "ly9_m1" ; + string_to_sw["L4B_stereo_pos"] = "ly9_m3" ; + string_to_sw["L4B_axial_ele"] = "ly10_m1" ; + string_to_sw["L4B_axial_pos"] = "ly10_m3" ; + string_to_sw["L5T_axial_ele"] = "ly11_m0" ; + string_to_sw["L5T_axial_pos"] = "ly11_m2" ; + string_to_sw["L5T_stereo_ele"] = "ly12_m0" ; + string_to_sw["L5T_stereo_pos"] = "ly12_m2" ; + string_to_sw["L5B_stereo_ele"] = "ly11_m1" ; + string_to_sw["L5B_stereo_pos"] = "ly11_m3" ; + string_to_sw["L5B_axial_ele"] = "ly12_m1" ; + string_to_sw["L5B_axial_pos"] = "ly12_m3" ; + string_to_sw["L6T_axial_ele"] = "ly13_m0" ; + string_to_sw["L6T_axial_pos"] = "ly13_m2" ; + string_to_sw["L6T_stereo_ele"] = "ly14_m0" ; + string_to_sw["L6T_stereo_pos"] = "ly14_m2" ; + string_to_sw["L6B_stereo_ele"] = "ly13_m1" ; + string_to_sw["L6B_stereo_pos"] = "ly13_m3" ; + string_to_sw["L6B_axial_ele"] = "ly14_m1" ; + string_to_sw["L6B_axial_pos"] = "ly14_m3" ; } //constructor From 6776f7999c1d260f00236cb2298453cd77c9e8ee Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 17 Sep 2019 16:38:50 -0700 Subject: [PATCH 112/314] Reduced memory leaks --- processors/src/TrackingProcessor.cxx | 63 +++++++++++++++++++--------- 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx index b5a192085..1251e8abd 100644 --- a/processors/src/TrackingProcessor.cxx +++ b/processors/src/TrackingProcessor.cxx @@ -16,12 +16,35 @@ void TrackingProcessor::initialize(TTree* tree) { } bool TrackingProcessor::process(IEvent* ievent) { + + + //Clean up + if (tracks_.size() > 0 ) { + for (std::vector::iterator it = tracks_.begin(); it != tracks_.end(); ++it) { + delete *it; + } + tracks_.clear(); + } + + if (hits_.size() > 0) { + for (std::vector::iterator it = hits_.begin(); it != hits_.end(); ++it) { + delete *it; + } + hits_.clear(); + } - + if (rawhits_.size() > 0) { + for (std::vector::iterator it = rawhits_.begin(); it != rawhits_.end(); ++it) { + delete *it; + } + rawhits_.clear(); + } + + tracks_.clear(); hits_.clear(); rawhits_.clear(); - + Event* event = static_cast (ievent); // Get the collection of 3D hits from the LCIO event. If no such collection // exist, a DataNotAvailableException is thrown @@ -40,8 +63,7 @@ bool TrackingProcessor::process(IEvent* ievent) { { raw_svt_hit_fits = event->getLCCollection(Collections::RAW_SVT_HIT_FITS); // Heap an LCRelation navigator which will allow faster access - rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); - + rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); } // Get all track collections from the event @@ -230,25 +252,26 @@ bool TrackingProcessor::process(IEvent* ievent) { rawHit->setADCs(hit_adcs); if (hasFits) - { - // Get the list of fit params associated with the raw tracker hit - EVENT::LCObjectVec rawTracker_hit_fits_list - = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); - + { + // Get the list of fit params associated with the raw tracker hit + EVENT::LCObjectVec rawTracker_hit_fits_list + = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); + // Get the list SVTFittedRawTrackerHit GenericObject associated with the SVTRawTrackerHit IMPL::LCGenericObjectImpl* hit_fit_param - = static_cast(rawTracker_hit_fits_list.at(0)); - + = static_cast(rawTracker_hit_fits_list.at(0)); + double fit_params[5] = { - (double)hit_fit_param->getDoubleVal(0), - (double)hit_fit_param->getDoubleVal(1), + (double)hit_fit_param->getDoubleVal(0), + (double)hit_fit_param->getDoubleVal(1), (double)hit_fit_param->getDoubleVal(2), - (double)hit_fit_param->getDoubleVal(3), - (double)hit_fit_param->getDoubleVal(4) + (double)hit_fit_param->getDoubleVal(3), + (double)hit_fit_param->getDoubleVal(4) }; - + rawHit->setFit(fit_params); - } + + } tracker_hit->addRawHit(rawHit); rawhits_.push_back(rawHit); @@ -265,12 +288,14 @@ bool TrackingProcessor::process(IEvent* ievent) { tracks_.push_back(track); }// tracks - + //delete + if (rawTracker_hit_fits_nav) { + delete rawTracker_hit_fits_nav; rawTracker_hit_fits_nav = nullptr;} + //event->addCollection("TracksInfo", &tracks_); //event->addCollection("TrackerHitsInfo", &hits_); //event->addCollection("TrackerHitsRawInfo", &rawhits_); - return true; } From f70fbeab2c901f2f47690d0786ce17f5df03ae7e Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Wed, 18 Sep 2019 17:28:22 -0700 Subject: [PATCH 113/314] clustersOnTracks processor config example --- processors/config/clustersOnTracks.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 processors/config/clustersOnTracks.py diff --git a/processors/config/clustersOnTracks.py b/processors/config/clustersOnTracks.py new file mode 100644 index 000000000..d6da50e26 --- /dev/null +++ b/processors/config/clustersOnTracks.py @@ -0,0 +1,24 @@ +import HpstrConf +import sys +p = HpstrConf.Process() + +# Library containing processors +p.libraries.append("libprocessors.so") + +#Processors + +clusters = HpstrConf.Processor('clusters','ClusterOnTrackProcessor') + +p.sequence = [clusters] + +p.input_files = [ + "/nfs/slac/g/hps2/pbutti/hps_data2/hps_010487/recon/hps_10487.02292_recon_3fbfd00b3.root" +] + +p.output_files = [ + "hps_10487.02292_hist_3fbfd00b3.root" +] + +#p.max_events = 1000 +p.printProcess() + From ef4610a94a4d427a732b180f6cc006de3accab10 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Wed, 18 Sep 2019 17:29:57 -0700 Subject: [PATCH 114/314] Added baseline loading for the Clusters on track histos --- analysis/include/ClusterHistos.h | 29 +- analysis/include/ModuleMapper.h | 38 +- analysis/src/ClusterHistos.cxx | 308 ++++++++---- analysis/src/ModuleMapper.cxx | 525 +++++++++++---------- processors/src/ClusterOnTrackProcessor.cxx | 7 +- 5 files changed, 554 insertions(+), 353 deletions(-) diff --git a/analysis/include/ClusterHistos.h b/analysis/include/ClusterHistos.h index 91a6c7555..75bfbfaac 100644 --- a/analysis/include/ClusterHistos.h +++ b/analysis/include/ClusterHistos.h @@ -3,10 +3,15 @@ #include "TFile.h" #include "HistoManager.h" +#include "TGraphErrors.h" +#include "TKey.h" +#include "TList.h" #include "TrackerHit.h" #include "RawSvtHit.h" +#include "ModuleMapper.h" + #include @@ -27,18 +32,36 @@ class ClusterHistos : public HistoManager{ void FillHistograms(TrackerHit* hit,float weight = 1.); //void BuildAxesMap(); + void setBaselineFitsDir(const std::string& baselineFits) {baselineFits_ = baselineFits;}; + bool LoadBaselineHistos(const std::string& baselineRun); + + //void setBaselineFits(const std::string& baselineFits){baselineFits_ = baselineFits;}; + //std::string getBaselineFits const () {return baselineFits_;}; + private: - std::vector layers{"ly0","ly1","ly2","ly3","ly4","ly5","ly6"}; - std::vector volumes{"top","bottom"}; - std::vector sides{"axial","stereo"}; + std::vector layers{"L0","L1","L2","L3","L4","L5","L6"}; + std::vector volumes{"T","B"}; + std::vector types{"axial","stereo"}; + std::vector side{"ele","pos"}; std::vector variables{"charge","cluSize"}; + + std::vector half_module_names{}; + std::map cluSizeMap; std::map chargeMap; + std::map chargeCorrectedMap; std::map cluPositionMap; + std::string baselineFits_{"/nfs/slac/g/hps3/svtTests/jlabSystem/baselines/fits/"}; + std::string baselineRun_{""}; + + std::map baselineGraphs; + + //TODO clean this + ModuleMapper *mmapper_; }; diff --git a/analysis/include/ModuleMapper.h b/analysis/include/ModuleMapper.h index 8a07cf779..725d010a9 100644 --- a/analysis/include/ModuleMapper.h +++ b/analysis/include/ModuleMapper.h @@ -1,20 +1,49 @@ #ifndef _MODULE_MAPPER_H_ #define _MODULE_MAPPER_H_ + #include +#include #include class ModuleMapper { public: - ModuleMapper(); - ModuleMapper(const int year) {year_ = year;}; + ModuleMapper(const int year = 2019); //TODO, clean up? ~ModuleMapper(); + + std::string getHwFromString(const std::string& key) {return string_to_hw[key];}; + std::string getSwFromString(const std::string& key) {return string_to_sw[key];}; + std::string getHwFromSw (const std::string& key) {return sw_to_hw[key];}; + std::string getSwFromHw (const std::string& key) {return hw_to_sw[key];}; + std::string getStringFromHw(const std::string& key) {return hw_to_string[key];}; + std::string getStringFromSw(const std::string& key) {return sw_to_string[key];}; + + //get list of string modules + + void getStrings (std::vector& strings) { + for (strmap_it it = string_to_hw.begin(); it!= string_to_hw.end(); ++it) + strings.push_back(it->first); + } - //Bidirectional maps could be used + //get list of hw names + void getHws (std::vector& hws) { + for (strmap_it it = hw_to_string.begin(); it!= hw_to_string.end(); ++it) + hws.push_back(it->first); + } + + //get list of sw names + void getSws (std::vector& sws) { + for (strmap_it it = hw_to_string.begin(); it!= hw_to_string.end(); ++it) + sws.push_back(it->first); + } + + + + //TODO Bidirectional maps could be used private: @@ -29,6 +58,9 @@ class ModuleMapper { std::map sw_to_string; std::map string_to_sw; + typedef std::map::iterator strmap_it; + + }; diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx index 355a2b726..994732051 100644 --- a/analysis/src/ClusterHistos.cxx +++ b/analysis/src/ClusterHistos.cxx @@ -1,157 +1,279 @@ #include "ClusterHistos.h" #include +#include "TCanvas.h" void ClusterHistos::Define1DHistos() { //TODO improve this naming scheme std::string h_name = ""; + + mmapper_ = new ModuleMapper(2019); //Cluster position histos1d[m_name+"_gz"] = plot1D(m_name+"_gz","Global Z [mm]",20000,-1000,2000); - //2D hits plots - for (unsigned int iv = 0 ; iv < volumes.size(); ++iv) { - for (unsigned int ily = 0; ily < layers.size(); ++ily) { - for (unsigned int is = 0; is < sides.size(); ++is) { - - h_name = m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_charge"; - histos1d[h_name] = plot1D(h_name,"charge",100,0,10000); - - h_name = m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_cluSize"; - histos1d[h_name] = plot1D(h_name,"cluSize",10,0,10); - cluSizeMap[h_name] = 0; - chargeMap[h_name] = 0.; - cluPositionMap[h_name] = 0.; - } - } - } + mmapper_->getStrings(half_module_names); + + for (unsigned int ihm = 0; ihmGetDirectory("baseline"); + + TList* keyList = dir->GetListOfKeys(); + TIter next(keyList); + TKey* key; + + //I assume that there are only TGraphErrors + //TObject* obj; + + while ( key = (TKey*)next()) { + //obj = key->ReadObj(); + //if (strcmp(obj->IsA()->GetName(),"TGraphErrors") != 0 ) + //continue; + + + //x values go from 0 to 512 (513 points) for L0-1. Last point is 0 + //x values go from 0 to 639 (640 points) for other layers + std::string graph_key = key->GetName(); + graph_key = graph_key.substr(graph_key.find("F"),4); + baselineGraphs[graph_key] = (TGraphErrors*) (dir->Get(key->GetName())); } + + //for (std::map::iterator it = baselineGraphs.begin(); it!=baselineGraphs.end(); ++it) + //std::cout<first<<" " <second->GetN()<GetN();point++) { + //Double_t x=-999; + //Double_t y=-999; + //baselineGraphs["F5H1"]->GetPoint(point,x,y); + //std::cout<Close(); + delete baselinesFile; + baselinesFile = nullptr; + + return true; } + + + + void ClusterHistos::FillHistograms(TrackerHit* hit,float weight) { TRefArray* rawhits_ = hit->getRawHits(); - int iv = -1; // 0 top, 1 bottom - int is = -1; // 0 axial, 1 stereo - int ily = -1; // 0-6 + //int iv = -1; // 0 top, 1 bottom + //int it = -1; // 0 axial, 1 stereo + //int ily = -1; // 0-6 //TODO do this better + //std::cout<<"Size:" <GetEntries()<GetEntries(); ++irh) { RawSvtHit * rawhit = static_cast(rawhits_->At(irh)); //rawhit layers go from 1 to 14. Example: RawHit->Layer1 is layer0 axial on top and layer0 stereo in bottom. - ily = (rawhit->getLayer() - 1) / 2; - - //Get the volume: even = top, odd = bottom - if (rawhit->getModule() % 2 == 0) - iv = 0; - else - iv = 1; - //top volume - if (!iv) { - //layer odd => axial / layer even => stereo - if (rawhit->getLayer() % 2 != 0) - is = 0; - else - is = 1; - } - //bottom volume - else { - //layer even => axial / layer odd => stereo - if (rawhit->getLayer() % 2 == 0) - is = 0; - else - is = 1; - } - //std::cout<<"ily:"<Fill(1e-5,weight); - + + swTag = "ly"+std::to_string(rawhit->getLayer())+"_m"+std::to_string(rawhit->getModule()); + + std::string key = mmapper_->getStringFromSw(swTag); + //std::cout<<"----"<getStringFromSw(swTag)<getAmp(); - - //2D cluster size - cluSizeMap [m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_cluSize"] ++; + chargeMap [m_name+"_"+key+"_charge"] += rawhit->getAmp(); + + double baseline = -999; + double strip = -999; + + //2D cluster corrected charge + baselineGraphs[mmapper_->getHwFromString(key)]->GetPoint(rawhit->getStrip(),strip,baseline); + + float sample0 = baseline - rawhit->getADCs()[0]; + float sample1 = baseline - rawhit->getADCs()[1]; + + chargeCorrectedMap[m_name+"_"+key+"_charge"] += (rawhit->getAmp() + sample0); + + histos2d[m_name+"_"+key+"_sample0_vs_Amp"]->Fill(rawhit->getAmp(),sample0,weight); + histos2d[m_name+"_"+key+"_sample1_vs_Amp"]->Fill(rawhit->getAmp(),sample1,weight); + + histos2d[m_name+"_"+key+"_sample0_vs_stripPos"]->Fill(rawhit->getStrip(),-sample0,weight); + histos2d[m_name+"_"+key+"_sample1_vs_stripPos"]->Fill(rawhit->getStrip(),-sample1,weight); + + + //2D cluster size1 + cluSizeMap [m_name+"_"+key+"_cluSize"] ++; //2D Weighted position numerator - cluPositionMap[m_name+"_"+volumes[iv]+"_"+layers[ily]+"_"+sides[is]+"_charge"] += rawhit->getAmp()*rawhit->getStrip(); + cluPositionMap[m_name+"_"+key+"_charge"] += rawhit->getAmp()*rawhit->getStrip(); //std::cout<<"rawhit->getStrip()::"<getStrip()<::iterator it = cluSizeMap.begin(); it!=cluSizeMap.end(); ++it ) { if (it->second != 0) { //std::cout<<"Filling..."<first<<" "<first]<first]->Fill(it->second,weight); cluSizeMap[it->first]= 0; } - } + }// fills the maps + + //TODO make this more efficient: useless to loop all over the possibilities for (std::map::iterator it = chargeMap.begin(); it!=chargeMap.end(); ++it ) { - //Avoid comparing to 0.0 + //TODO make it better + //Avoid comparing to 0.0 and check if there is a charge deposit on this if (it->second > 1e-6) { - //std::cout<<"Filling..."<first<<" "<first]<first).substr(0,(it->first).find("_charge")); + //it->second holds the charge //it->first = charge histogram name. double charge = it->second; histos1d[it->first]->Fill(charge,weight); double weighted_pos = cluPositionMap[it->first] / (charge); + double chargeCorrected = chargeCorrectedMap[it->first]; //std::cout<<"weighted pos "<first+"_vs_stripPos"]->Fill(weighted_pos,charge,weight); + + // Fill the baseline corrected charge + histos2d[it->first+"_corrected_vs_stripPos"]->Fill(weighted_pos,chargeCorrected,weight); + + //Fill local vs global + + histos2d[plotID+"_stripPos_vs_gy"]->Fill(fabs(hit->getGlobalY()),weighted_pos,weight); + double globRad = sqrt(hit->getGlobalX() * hit->getGlobalX() + hit->getGlobalY()+hit->getGlobalY()); histos2d[it->first+"_vs_globRad"]->Fill(globRad,charge,weight); - chargeMap[it->first] = 0.0; - cluPositionMap[it->first] = 0.0; - } + + + chargeMap[it->first] = 0.0; + chargeCorrectedMap[it->first] = 0.0; + cluPositionMap[it->first] = 0.0; + + } } histos1d[m_name+"_gz"]->Fill(hit->getGlobalZ(),weight); //1D //histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); //2D if (hit->getGlobalZ() < 50 && hit->getGlobalZ() > 40) { - histos2d[m_name+"_charge_L0_top_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); - histos2d[m_name+"_charge_L0_top_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0T_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0T_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); } - + if (hit->getGlobalZ() < 60 && hit->getGlobalZ() > 55) { - histos2d[m_name+"_charge_L0_bottom_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); - histos2d[m_name+"_charge_L0_bottom_vs_gy"]->Fill(hit->getGlobalY(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0B_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0B_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); } - } diff --git a/analysis/src/ModuleMapper.cxx b/analysis/src/ModuleMapper.cxx index d7d6ce636..371e574c4 100644 --- a/analysis/src/ModuleMapper.cxx +++ b/analysis/src/ModuleMapper.cxx @@ -1,260 +1,279 @@ #include "ModuleMapper.h" +#include -ModuleMapper::ModuleMapper() { +ModuleMapper::ModuleMapper(const int year) { - hw_to_sw["F0H0"] = "ly1_m0"; - hw_to_sw["F0H1"] = "ly2_m0"; - hw_to_sw["F0H2"] = "ly3_m0"; - hw_to_sw["F0H3"] = "ly4_m0"; - hw_to_sw["F1H0"] = "ly4_m1"; - hw_to_sw["F1H1"] = "ly3_m1"; - hw_to_sw["F1H2"] = "ly2_m1"; - hw_to_sw["F1H3"] = "ly1_m1"; - hw_to_sw["F2H0"] = "ly5_m0"; - hw_to_sw["F2H1"] = "ly6_m0"; - hw_to_sw["F2H2"] = "ly8_m0"; - hw_to_sw["F2H3"] = "ly7_m0"; - hw_to_sw["F3H0"] = "ly7_m1"; - hw_to_sw["F3H1"] = "ly8_m1"; - hw_to_sw["F3H2"] = "ly5_m1"; - hw_to_sw["F3H3"] = "ly6_m1"; - hw_to_sw["F4H0"] = "ly9_m0"; - hw_to_sw["F4H1"] = "ly9_m2"; - hw_to_sw["F4H2"] = "ly10_m0"; - hw_to_sw["F4H3"] = "ly10_m2"; - hw_to_sw["F5H0"] = "ly9_m1"; - hw_to_sw["F5H1"] = "ly9_m3"; - hw_to_sw["F5H2"] = "ly10_m1"; - hw_to_sw["F5H3"] = "ly10_m3"; - hw_to_sw["F6H0"] = "ly11_m0"; - hw_to_sw["F6H1"] = "ly11_m2"; - hw_to_sw["F6H2"] = "ly12_m0"; - hw_to_sw["F6H3"] = "ly12_m2"; - hw_to_sw["F7H0"] = "ly11_m1"; - hw_to_sw["F7H1"] = "ly11_m3"; - hw_to_sw["F7H2"] = "ly12_m1"; - hw_to_sw["F7H3"] = "ly12_m3"; - hw_to_sw["F8H0"] = "ly13_m0"; - hw_to_sw["F8H1"] = "ly13_m2"; - hw_to_sw["F8H2"] = "ly14_m0"; - hw_to_sw["F8H3"] = "ly14_m2"; - hw_to_sw["F9H0"] = "ly13_m1"; - hw_to_sw["F9H1"] = "ly13_m3"; - hw_to_sw["F9H2"] = "ly14_m1"; - hw_to_sw["F9H3"] = "ly14_m3"; + if (year == 2019) { + + //TODO Insert the correct mapping!! + //Cameron mapping = > This should be the correct mapping + //https://docs.google.com/spreadsheets/d/1sVtYEppxKlwJvpniemKf6EtFqK8qN0ZnDRExR_eqqZw/edit#gid=1695271832 + //hw_to_sw["F3H0"] = "ly7_m1"; + //hw_to_sw["F3H1"] = "ly8_m1"; + //hw_to_sw["F3H2"] = "ly5_m1"; + //hw_to_sw["F3H3"] = "ly6_m1"; - sw_to_hw["ly1_m0"] = "F0H0" ; - sw_to_hw["ly2_m0"] = "F0H1" ; - sw_to_hw["ly3_m0"] = "F0H2" ; - sw_to_hw["ly4_m0"] = "F0H3" ; - sw_to_hw["ly4_m1"] = "F1H0" ; - sw_to_hw["ly3_m1"] = "F1H1" ; - sw_to_hw["ly2_m1"] = "F1H2" ; - sw_to_hw["ly1_m1"] = "F1H3" ; - sw_to_hw["ly5_m0"] = "F2H0" ; - sw_to_hw["ly6_m0"] = "F2H1" ; - sw_to_hw["ly8_m0"] = "F2H2" ; - sw_to_hw["ly7_m0"] = "F2H3" ; - sw_to_hw["ly7_m1"] = "F3H0" ; - sw_to_hw["ly8_m1"] = "F3H1" ; - sw_to_hw["ly5_m1"] = "F3H2" ; - sw_to_hw["ly6_m1"] = "F3H3" ; - sw_to_hw["ly9_m0"] = "F4H0" ; - sw_to_hw["ly9_m2"] = "F4H1" ; - sw_to_hw["ly10_m0"] = "F4H2"; - sw_to_hw["ly10_m2"] = "F4H3"; - sw_to_hw["ly9_m1"] = "F5H0" ; - sw_to_hw["ly9_m3"] = "F5H1" ; - sw_to_hw["ly10_m1"] = "F5H2"; - sw_to_hw["ly10_m3"] = "F5H3"; - sw_to_hw["ly11_m0"] = "F6H0"; - sw_to_hw["ly11_m2"] = "F6H1"; - sw_to_hw["ly12_m0"] = "F6H2"; - sw_to_hw["ly12_m2"] = "F6H3"; - sw_to_hw["ly11_m1"] = "F7H0"; - sw_to_hw["ly11_m3"] = "F7H1"; - sw_to_hw["ly12_m1"] = "F7H2"; - sw_to_hw["ly12_m3"] = "F7H3"; - sw_to_hw["ly13_m0"] = "F8H0"; - sw_to_hw["ly13_m2"] = "F8H1"; - sw_to_hw["ly14_m0"] = "F8H2"; - sw_to_hw["ly14_m2"] = "F8H3"; - sw_to_hw["ly13_m1"] = "F9H0"; - sw_to_hw["ly13_m3"] = "F9H1"; - sw_to_hw["ly14_m1"] = "F9H2"; - sw_to_hw["ly14_m3"] = "F9H3"; - - // HW to string and viceversa - //string format : ___ - - hw_to_string["F0H0"] = "L0T_axial"; - hw_to_string["F0H1"] = "L0T_stereo"; - hw_to_string["F0H2"] = "L1T_axial"; - hw_to_string["F0H3"] = "L1T_stereo"; - hw_to_string["F1H0"] = "L1B_axial"; - hw_to_string["F1H1"] = "L1B_stereo"; - hw_to_string["F1H2"] = "L0B_axial"; - hw_to_string["F1H3"] = "L0B_stereo"; - hw_to_string["F2H0"] = "L2T_axial"; - hw_to_string["F2H1"] = "L2T_stereo"; - hw_to_string["F2H2"] = "L3T_axial"; - hw_to_string["F2H3"] = "L3T_stereo"; - hw_to_string["F3H0"] = "L3B_axial"; - hw_to_string["F3H1"] = "L3B_stereo"; - hw_to_string["F3H2"] = "L2B_axial"; - hw_to_string["F3H3"] = "L2B_stereo"; - hw_to_string["F4H0"] = "L4T_axial_ele"; - hw_to_string["F4H1"] = "L4T_axial_pos"; - hw_to_string["F4H2"] = "L4T_stereo_ele"; - hw_to_string["F4H3"] = "L4T_stereo_pos"; - hw_to_string["F5H0"] = "L4B_stereo_ele"; - hw_to_string["F5H1"] = "L4B_stereo_pos"; - hw_to_string["F5H2"] = "L4B_axial_ele"; - hw_to_string["F5H3"] = "L4B_axial_pos"; - hw_to_string["F6H0"] = "L5T_axial_ele"; - hw_to_string["F6H1"] = "L5T_axial_pos"; - hw_to_string["F6H2"] = "L5T_stereo_ele"; - hw_to_string["F6H3"] = "L5T_stereo_pos"; - hw_to_string["F7H0"] = "L5B_stereo_ele"; - hw_to_string["F7H1"] = "L5B_stereo_pos"; - hw_to_string["F7H2"] = "L5B_axial_ele"; - hw_to_string["F7H3"] = "L5B_axial_pos"; - hw_to_string["F8H0"] = "L6T_axial_ele"; - hw_to_string["F8H1"] = "L6T_axial_pos"; - hw_to_string["F8H2"] = "L6T_stereo_ele"; - hw_to_string["F8H3"] = "L6T_stereo_pos"; - hw_to_string["F9H0"] = "L6B_stereo_ele"; - hw_to_string["F9H1"] = "L6B_stereo_pos"; - hw_to_string["F9H2"] = "L6B_axial_ele"; - hw_to_string["F9H3"] = "L6B_axial_pos"; - - string_to_hw["L0T_axial"] = "F0H0"; - string_to_hw["L0T_stereo"] = "F0H1"; - string_to_hw["L1T_axial"] = "F0H2"; - string_to_hw["L1T_stereo"] = "F0H3"; - string_to_hw["L1B_axial"] = "F1H0"; - string_to_hw["L1B_stereo"] = "F1H1"; - string_to_hw["L0B_axial"] = "F1H2"; - string_to_hw["L0B_stereo"] = "F1H3"; - string_to_hw["L2T_axial"] = "F2H0"; - string_to_hw["L2T_stereo"] = "F2H1"; - string_to_hw["L3T_axial"] = "F2H2"; - string_to_hw["L3T_stereo"] = "F2H3"; - string_to_hw["L3B_axial"] = "F3H0"; - string_to_hw["L3B_stereo"] = "F3H1"; - string_to_hw["L2B_axial"] = "F3H2"; - string_to_hw["L2B_stereo"] = "F3H3"; - string_to_hw["L4T_axial_ele"] = "F4H0"; - string_to_hw["L4T_axial_pos"] = "F4H1"; - string_to_hw["L4T_stereo_ele"] = "F4H2"; - string_to_hw["L4T_stereo_pos"] = "F4H3"; - string_to_hw["L4B_stereo_ele"] = "F5H0"; - string_to_hw["L4B_stereo_pos"] = "F5H1"; - string_to_hw["L4B_axial_ele"] = "F5H2"; - string_to_hw["L4B_axial_pos"] = "F5H3"; - string_to_hw["L5T_axial_ele"] = "F6H0"; - string_to_hw["L5T_axial_pos"] = "F6H1"; - string_to_hw["L5T_stereo_ele"] = "F6H2"; - string_to_hw["L5T_stereo_pos"] = "F6H3"; - string_to_hw["L5B_stereo_ele"] = "F7H0"; - string_to_hw["L5B_stereo_pos"] = "F7H1"; - string_to_hw["L5B_axial_ele"] = "F7H2"; - string_to_hw["L5B_axial_pos"] = "F7H3"; - string_to_hw["L6T_axial_ele"] = "F8H0"; - string_to_hw["L6T_axial_pos"] = "F8H1"; - string_to_hw["L6T_stereo_ele"] = "F8H2"; - string_to_hw["L6T_stereo_pos"] = "F8H3"; - string_to_hw["L6B_stereo_ele"] = "F9H0"; - string_to_hw["L6B_stereo_pos"] = "F9H1"; - string_to_hw["L6B_axial_ele"] = "F9H2"; - string_to_hw["L6B_axial_pos"] = "F9H3"; - - - //sw to string - //string format : ___ - - sw_to_string["ly1_m0"] = "L0T_axial"; - sw_to_string["ly2_m0"] = "L0T_stereo"; - sw_to_string["ly3_m0"] = "L1T_axial"; - sw_to_string["ly4_m0"] = "L1T_stereo"; - sw_to_string["ly4_m1"] = "L1B_axial"; - sw_to_string["ly3_m1"] = "L1B_stereo"; - sw_to_string["ly2_m1"] = "L0B_axial"; - sw_to_string["ly1_m1"] = "L0B_stereo"; - sw_to_string["ly5_m0"] = "L2T_axial"; - sw_to_string["ly6_m0"] = "L2T_stereo"; - sw_to_string["ly8_m0"] = "L3T_axial"; - sw_to_string["ly7_m0"] = "L3T_stereo"; - sw_to_string["ly7_m1"] = "L3B_axial"; - sw_to_string["ly8_m1"] = "L3B_stereo"; - sw_to_string["ly5_m1"] = "L2B_axial"; - sw_to_string["ly6_m1"] = "L2B_stereo"; - sw_to_string["ly9_m0"] = "L4T_axial_ele"; - sw_to_string["ly9_m2"] = "L4T_axial_pos"; - sw_to_string["ly10_m0"] = "L4T_stereo_ele"; - sw_to_string["ly10_m2"] = "L4T_stereo_pos"; - sw_to_string["ly9_m1"] = "L4B_stereo_ele"; - sw_to_string["ly9_m3"] = "L4B_stereo_pos"; - sw_to_string["ly10_m1"] = "L4B_axial_ele"; - sw_to_string["ly10_m3"] = "L4B_axial_pos"; - sw_to_string["ly11_m0"] = "L5T_axial_ele"; - sw_to_string["ly11_m2"] = "L5T_axial_pos"; - sw_to_string["ly12_m0"] = "L5T_stereo_ele"; - sw_to_string["ly12_m2"] = "L5T_stereo_pos"; - sw_to_string["ly11_m1"] = "L5B_stereo_ele"; - sw_to_string["ly11_m3"] = "L5B_stereo_pos"; - sw_to_string["ly12_m1"] = "L5B_axial_ele"; - sw_to_string["ly12_m3"] = "L5B_axial_pos"; - sw_to_string["ly13_m0"] = "L6T_axial_ele"; - sw_to_string["ly13_m2"] = "L6T_axial_pos"; - sw_to_string["ly14_m0"] = "L6T_stereo_ele"; - sw_to_string["ly14_m2"] = "L6T_stereo_pos"; - sw_to_string["ly13_m1"] = "L6B_stereo_ele"; - sw_to_string["ly13_m3"] = "L6B_stereo_pos"; - sw_to_string["ly14_m1"] = "L6B_axial_ele"; - sw_to_string["ly14_m3"] = "L6B_axial_pos"; - - - string_to_sw["L0T_axial"] = "ly1_m0" ; - string_to_sw["L0T_stereo"] = "ly2_m0" ; - string_to_sw["L1T_axial"] = "ly3_m0" ; - string_to_sw["L1T_stereo"] = "ly4_m0" ; - string_to_sw["L1B_axial"] = "ly4_m1" ; - string_to_sw["L1B_stereo"] = "ly3_m1" ; - string_to_sw["L0B_axial"] = "ly2_m1" ; - string_to_sw["L0B_stereo"] = "ly1_m1" ; - string_to_sw["L2T_axial"] = "ly5_m0" ; - string_to_sw["L2T_stereo"] = "ly6_m0" ; - string_to_sw["L3T_axial"] = "ly8_m0" ; - string_to_sw["L3T_stereo"] = "ly7_m0" ; - string_to_sw["L3B_axial"] = "ly7_m1" ; - string_to_sw["L3B_stereo"] = "ly8_m1" ; - string_to_sw["L2B_axial"] = "ly5_m1" ; - string_to_sw["L2B_stereo"] = "ly6_m1" ; - string_to_sw["L4T_axial_ele"] = "ly9_m0" ; - string_to_sw["L4T_axial_pos"] = "ly9_m2" ; - string_to_sw["L4T_stereo_ele"] = "ly10_m0" ; - string_to_sw["L4T_stereo_pos"] = "ly10_m2" ; - string_to_sw["L4B_stereo_ele"] = "ly9_m1" ; - string_to_sw["L4B_stereo_pos"] = "ly9_m3" ; - string_to_sw["L4B_axial_ele"] = "ly10_m1" ; - string_to_sw["L4B_axial_pos"] = "ly10_m3" ; - string_to_sw["L5T_axial_ele"] = "ly11_m0" ; - string_to_sw["L5T_axial_pos"] = "ly11_m2" ; - string_to_sw["L5T_stereo_ele"] = "ly12_m0" ; - string_to_sw["L5T_stereo_pos"] = "ly12_m2" ; - string_to_sw["L5B_stereo_ele"] = "ly11_m1" ; - string_to_sw["L5B_stereo_pos"] = "ly11_m3" ; - string_to_sw["L5B_axial_ele"] = "ly12_m1" ; - string_to_sw["L5B_axial_pos"] = "ly12_m3" ; - string_to_sw["L6T_axial_ele"] = "ly13_m0" ; - string_to_sw["L6T_axial_pos"] = "ly13_m2" ; - string_to_sw["L6T_stereo_ele"] = "ly14_m0" ; - string_to_sw["L6T_stereo_pos"] = "ly14_m2" ; - string_to_sw["L6B_stereo_ele"] = "ly13_m1" ; - string_to_sw["L6B_stereo_pos"] = "ly13_m3" ; - string_to_sw["L6B_axial_ele"] = "ly14_m1" ; - string_to_sw["L6B_axial_pos"] = "ly14_m3" ; + //This is Omar's mapping, which is what is in the DB + //WARNING: Might be wrong. + std::cout<<"WARNING: ModuleMapper: using a mapping that might be wrong"<LoadBaselineHistos("010458")) + std::cout<<"WARNING: baselines not loaded in Cluster on Track histos."<Define1DHistos(); clusterHistos->Define2DHistos(); tree_= tree; @@ -35,7 +39,8 @@ void ClusterOnTrackProcessor::finalize() { clusterHistos->saveHistos(outF_,""); //outF_->Close(); - + delete clusterHistos; + clusterHistos = nullptr; } DECLARE_PROCESSOR(ClusterOnTrackProcessor); From ea7341d6fedc28efdac77b9164a169405efce187 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Wed, 18 Sep 2019 17:40:49 -0700 Subject: [PATCH 115/314] Clean up of the histograms at the destructior --- analysis/include/HistoManager.h | 4 ++-- analysis/src/HistoManager.cxx | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/analysis/include/HistoManager.h b/analysis/include/HistoManager.h index bb93c7447..f2e711857 100644 --- a/analysis/include/HistoManager.h +++ b/analysis/include/HistoManager.h @@ -16,8 +16,8 @@ class HistoManager { HistoManager() {m_name = "default";} HistoManager(const std::string& inputName) {m_name=inputName;}; - //Todo add proper delete!! - virtual ~HistoManager(){}; + + virtual ~HistoManager(); TH3F* get3dHisto(const std::string& str) { return histos3d[str]; diff --git a/analysis/src/HistoManager.cxx b/analysis/src/HistoManager.cxx index ec5465dc9..1da589948 100644 --- a/analysis/src/HistoManager.cxx +++ b/analysis/src/HistoManager.cxx @@ -4,6 +4,34 @@ #include "TClass.h" +HistoManager::~HistoManager() { + + std::cout<<"Cleaning up HistoManager"<second) { + delete (it->second); + (it->second) = nullptr; + } + } + histos1d.clear(); + + for (it2d it = histos2d.begin(); it!=histos2d.end(); ++it) { + if (it->second) { + delete (it->second); + (it->second) = nullptr; + } + } + histos2d.clear(); + + for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { + if (it->second) { + delete (it->second); + (it->second) = nullptr; + } + } + histos3d.clear(); +} void HistoManager::GetHistosFromFile(TFile* inFile, const std::string& name, const std::string& folder) { From 446b660d7af075cf325dd588e4c387a6407a90cb Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Wed, 18 Sep 2019 18:12:42 -0700 Subject: [PATCH 116/314] updates to cluster hists --- analysis/include/ClusterHistos.h | 12 +++-------- analysis/src/ClusterHistos.cxx | 36 +++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/analysis/include/ClusterHistos.h b/analysis/include/ClusterHistos.h index 75bfbfaac..2a1dfb08e 100644 --- a/analysis/include/ClusterHistos.h +++ b/analysis/include/ClusterHistos.h @@ -18,9 +18,8 @@ class ClusterHistos : public HistoManager{ public: - ClusterHistos(const std::string& inputName):HistoManager(inputName) - {m_name = inputName; - } + ClusterHistos(const std::string& inputName); + ~ClusterHistos(); virtual void Define3DHistos(){}; virtual void Define2DHistos(); @@ -41,10 +40,6 @@ class ClusterHistos : public HistoManager{ private: - std::vector layers{"L0","L1","L2","L3","L4","L5","L6"}; - std::vector volumes{"T","B"}; - std::vector types{"axial","stereo"}; - std::vector side{"ele","pos"}; std::vector variables{"charge","cluSize"}; std::vector half_module_names{}; @@ -61,8 +56,7 @@ class ClusterHistos : public HistoManager{ std::map baselineGraphs; //TODO clean this - ModuleMapper *mmapper_; - + ModuleMapper *mmapper_{nullptr}; }; diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx index 994732051..6963d9a61 100644 --- a/analysis/src/ClusterHistos.cxx +++ b/analysis/src/ClusterHistos.cxx @@ -2,13 +2,43 @@ #include #include "TCanvas.h" +ClusterHistos::ClusterHistos(const std::string& inputName):HistoManager(inputName) { + m_name = inputName; + mmapper_ = new ModuleMapper(2019); +} + +ClusterHistos::~ClusterHistos() { + + std::cout<<"Cleaning ClusterHistos"<::iterator it = baselineGraphs.begin(); + it!=baselineGraphs.end(); ++it) { + if (it->second) { + delete (it->second); + it->second = nullptr; + } + } + baselineGraphs.clear(); +} + + void ClusterHistos::Define1DHistos() { //TODO improve this naming scheme std::string h_name = ""; - - mmapper_ = new ModuleMapper(2019); - + //Cluster position histos1d[m_name+"_gz"] = plot1D(m_name+"_gz","Global Z [mm]",20000,-1000,2000); From 79dd1cd06f88b5a2c52ce7501e985c2c10e15eff Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 19 Sep 2019 10:50:09 -0700 Subject: [PATCH 117/314] Small changes to run on cbravo-hps --- analysis/include/ClusterHistos.h | 2 +- setup.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/analysis/include/ClusterHistos.h b/analysis/include/ClusterHistos.h index 75bfbfaac..15ff47888 100644 --- a/analysis/include/ClusterHistos.h +++ b/analysis/include/ClusterHistos.h @@ -55,7 +55,7 @@ class ClusterHistos : public HistoManager{ std::map chargeCorrectedMap; std::map cluPositionMap; - std::string baselineFits_{"/nfs/slac/g/hps3/svtTests/jlabSystem/baselines/fits/"}; + std::string baselineFits_{"/nfs/hps3/svtTests/jlabSystem/baselines/fits/"}; std::string baselineRun_{""}; std::map baselineGraphs; diff --git a/setup.sh b/setup.sh index 34c940b5c..a0af3df02 100644 --- a/setup.sh +++ b/setup.sh @@ -1,3 +1,6 @@ #!/bin/bash #export PYTHONPATH=/data/src/hpstr/processing/python:$PYTHONPATH export PYTHONPATH=/data/src/hpstr/install/lib/python:$PYTHONPATH + +export PATH=/data/src/hpstr/install/bin:$PATH +export LD_LIBRARY_PATH=/data/src/hpstr/install/lib:$LD_LIBRARY_PATH From 77230d1b7e3eb9e7da371a06aa90c260f030f356 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 19 Sep 2019 19:00:27 -0700 Subject: [PATCH 118/314] Make Clusters On Track Processor configurable --- processors/include/ClusterOnTrackProcessor.h | 14 +++++++++++++- processors/src/ClusterOnTrackProcessor.cxx | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/processors/include/ClusterOnTrackProcessor.h b/processors/include/ClusterOnTrackProcessor.h index 73ddf991d..502acd602 100644 --- a/processors/include/ClusterOnTrackProcessor.h +++ b/processors/include/ClusterOnTrackProcessor.h @@ -29,10 +29,22 @@ class ClusterOnTrackProcessor : public Processor { virtual void initialize(TTree* tree); virtual void finalize(); + + virtual void configure(const ParameterSet& parameters); + + void setBaselineFits(const std::string& baselineFits,const std::string& baselineRun){ + baselineFits_ = baselineFits; + baselineRun_ = baselineRun; + }; + private: - + ClusterHistos* clusterHistos; + + std::string baselineFits_{""}; + std::string baselineRun_{""}; + //TODO Change this to be held from HPSEvent TTree* tree_; std::vector *tracks_{}; diff --git a/processors/src/ClusterOnTrackProcessor.cxx b/processors/src/ClusterOnTrackProcessor.cxx index 1520f58c6..2cedde43e 100644 --- a/processors/src/ClusterOnTrackProcessor.cxx +++ b/processors/src/ClusterOnTrackProcessor.cxx @@ -5,11 +5,22 @@ ClusterOnTrackProcessor::ClusterOnTrackProcessor(const std::string& name, Proces //TODO CHECK THIS DESTRUCTOR ClusterOnTrackProcessor::~ClusterOnTrackProcessor(){} + +void ClusterOnTrackProcessor::configure(const ParameterSet& parameters) { + + baselineFits_ = parameters.getString("BaselineFits"); + baselineRun_ = parameters.getString("BaselineRun"); + std::cout<<"Configured: "<LoadBaselineHistos("010458")) - std::cout<<"WARNING: baselines not loaded in Cluster on Track histos."<setBaselineFitsDir(baselineFits_); + if (!clusterHistos->LoadBaselineHistos(baselineRun_)) + std::cout<<"WARNING: baselines not loaded in Cluster on Track histos."<Define1DHistos(); clusterHistos->Define2DHistos(); From eb2ade1c77661cc4d19f83f0ebf25f6ae6069164 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 26 Sep 2019 07:23:07 -0700 Subject: [PATCH 119/314] Fixes to cluster plots when missing baselines. Added global positions plots for L0 --- analysis/src/ClusterHistos.cxx | 41 +++++++++++++++------- processors/src/ClusterOnTrackProcessor.cxx | 5 +++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx index 6963d9a61..fc98abb8d 100644 --- a/analysis/src/ClusterHistos.cxx +++ b/analysis/src/ClusterHistos.cxx @@ -58,31 +58,44 @@ void ClusterHistos::Define1DHistos() { void ClusterHistos::Define2DHistos() { std::string h_name = ""; - histos2d[m_name+"_charge_L0_top_vs_gx"] = plot2D(m_name+"_charge_L0_top_vs_gx", - "Global X [mm] ",200,-100,100, - "edep",500,0,10000); int nbins = 1000; - float pitch = 0.050; + float pitch = 0.055; float startY = 0.700; histos2d[m_name+"_charge_L0T_vs_gy"] = plot2D(m_name+"_charge_L0T_vs_gy", "Global Y [mm]",nbins,startY,(nbins+1)*pitch, - "edep",100,0,10000); + "edep",100,0,1e-5); histos2d[m_name+"_charge_L0T_vs_gx"] = plot2D(m_name+"_charge_L0T_vs_gx", - "Global X [mm] ",200,-100,100, - "edep",100,0,10000); + "Global X [mm] ",80,-20,20, + "edep",100,0,1e-5); histos2d[m_name+"_charge_L0B_vs_gy"] = plot2D(m_name+"_charge_L0B_vs_gy", "Global Y [mm]",nbins,startY,(nbins+1)*pitch, - "edep",100,0,10000); + "edep",100,0,1e-5); histos2d[m_name+"_charge_L0B_vs_gx"] = plot2D(m_name+"_charge_L0B_vs_gx", - "Global X [mm] ",200,-100,100, - "edep",100,0,10000); + "Global X [mm] ",80,-20,20, + "edep",100,0,1e-5); + + + // location of the hits + + histos2d[m_name+"_gy_L0T_vs_gx"] = plot2D(m_name+"_gy_L0T_vs_gx", + "Global X [mm] ",80,-20,20, + "Global Y [mm]",100,0,5); + + + + histos2d[m_name+"_gy_L0B_vs_gx"] = plot2D(m_name+"_gy_L0B_vs_gx", + "Global X [mm] ",80,-20,20, + "Global Y [mm]",100,0,5); + + + //bin size must be multiple of 20 adc counts @@ -160,7 +173,7 @@ bool ClusterHistos::LoadBaselineHistos(const std::string& baselineRun) { //I assume that there are only TGraphErrors //TObject* obj; - while ( key = (TKey*)next()) { + while ( (key = (TKey*)next())) { //obj = key->ReadObj(); //if (strcmp(obj->IsA()->GetName(),"TGraphErrors") != 0 ) //continue; @@ -226,7 +239,8 @@ void ClusterHistos::FillHistograms(TrackerHit* hit,float weight) { double strip = -999; //2D cluster corrected charge - baselineGraphs[mmapper_->getHwFromString(key)]->GetPoint(rawhit->getStrip(),strip,baseline); + if (baselineGraphs[mmapper_->getHwFromString(key)]) + baselineGraphs[mmapper_->getHwFromString(key)]->GetPoint(rawhit->getStrip(),strip,baseline); float sample0 = baseline - rawhit->getADCs()[0]; float sample1 = baseline - rawhit->getADCs()[1]; @@ -298,11 +312,14 @@ void ClusterHistos::FillHistograms(TrackerHit* hit,float weight) { //histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); //2D if (hit->getGlobalZ() < 50 && hit->getGlobalZ() > 40) { + histos2d[m_name+"_gy_L0T_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight); histos2d[m_name+"_charge_L0T_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); histos2d[m_name+"_charge_L0T_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); + } if (hit->getGlobalZ() < 60 && hit->getGlobalZ() > 55) { + histos2d[m_name+"_gy_L0B_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight); histos2d[m_name+"_charge_L0B_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); histos2d[m_name+"_charge_L0B_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); } diff --git a/processors/src/ClusterOnTrackProcessor.cxx b/processors/src/ClusterOnTrackProcessor.cxx index 2cedde43e..588cc2c53 100644 --- a/processors/src/ClusterOnTrackProcessor.cxx +++ b/processors/src/ClusterOnTrackProcessor.cxx @@ -38,6 +38,11 @@ bool ClusterOnTrackProcessor::process(IEvent* ievent) { for (int itrack = 0; itracksize();itrack++) { Track *track = tracks_->at(itrack); //Loop on hits + if (!track->getSvtHits()) { + std::cout<<"WARNING::track doesn't have hits associated to it"<getSvtHits()->GetEntries(); ++ihit) { TrackerHit* hit3d = (TrackerHit*) track->getSvtHits()->At(ihit); clusterHistos->FillHistograms(hit3d,1.); From f0162dd42ac53069e0e484a4284869e1bcd2313e Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Fri, 27 Sep 2019 09:04:56 -0700 Subject: [PATCH 120/314] remove -r flag to decide if running on ROOT or LCIO files --- processing/include/Process.h | 4 ++++ processing/src/Process.cxx | 7 +++++++ processing/src/hpstr.cxx | 14 +++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/processing/include/Process.h b/processing/include/Process.h index 1ef58067a..f0c604b6b 100644 --- a/processing/include/Process.h +++ b/processing/include/Process.h @@ -73,6 +73,10 @@ class Process { /** Request that the processing finish with this event. */ void requestFinish() { event_limit_=0; } + //TODO add a check on consistent extensions of the input files + /** Check if the input_files_ are rootFiles */ + bool processRootFiles(); + private: /** Reader used to parse either binary or EVIO files. */ diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index dbfd102ab..6abd3ca22 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -12,6 +12,13 @@ Process::Process() {} //TODO Fix this better +bool Process::processRootFiles() { + if ((input_files_[0]).find(".root") != std::string::npos) + return true; + + return false; +} + void Process::runOnRoot() { try { int n_events_processed = 0; diff --git a/processing/src/hpstr.cxx b/processing/src/hpstr.cxx index d1196a550..09a620a6d 100644 --- a/processing/src/hpstr.cxx +++ b/processing/src/hpstr.cxx @@ -30,11 +30,7 @@ int main(int argc, char **argv) { } bool processRoot = false; - if (strstr(argv[1],"-r")) { - processRoot=true; - std::cout<<"Processing root file"<processRootFiles()) { + std::cout<<"---- [ hpstr ]: Running on ROOT Files --------" << std::endl; p->runOnRoot(); - else + } + else { + std::cout<<"---- [ hpstr ]: Running on LCIO Files --------" << std::endl; p->run(); + } std::cout << "---- [ hpstr ]: Event processing complete --------" << std::endl; From e4b9776a10b449509be6c04edea49f21fc77cd6b Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Fri, 27 Sep 2019 14:59:01 -0700 Subject: [PATCH 121/314] Use of utilities for building Hipster objects in TrackingProcessor --- processors/include/utilities.h | 5 +- processors/src/TrackingProcessor.cxx | 197 +++------------------------ processors/src/utilities.cxx | 13 +- 3 files changed, 29 insertions(+), 186 deletions(-) diff --git a/processors/include/utilities.h b/processors/include/utilities.h index 4b21e3ded..51060e631 100644 --- a/processors/include/utilities.h +++ b/processors/include/utilities.h @@ -11,6 +11,8 @@ #include #include +#include + //-----------// // hpstr // //-----------// @@ -33,7 +35,8 @@ namespace utils { TrackerHit* buildTrackerHit(IMPL::TrackerHitImpl* lc_trackerHit); bool addRawInfoTo3dHit(TrackerHit* tracker_hit, IMPL::TrackerHitImpl* lc_tracker_hit, - EVENT::LCCollection* raw_svt_fits); + EVENT::LCCollection* raw_svt_fits, + std::vector* rawHits = nullptr); bool isUsedByTrack(IMPL::TrackerHitImpl* lc_tracker_hit, diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx index 1251e8abd..eebee4185 100644 --- a/processors/src/TrackingProcessor.cxx +++ b/processors/src/TrackingProcessor.cxx @@ -1,5 +1,6 @@ #include "TrackingProcessor.h" +#include "utilities.h" TrackingProcessor::TrackingProcessor(const std::string& name, Process& process) : Processor(name, process) { @@ -76,211 +77,45 @@ bool TrackingProcessor::process(IEvent* ievent) { // Get a LCIO Track from the LCIO event EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); - // Add a track to the event - Track* track = new Track(); - - // Set the track parameters - track->setTrackParameters(lc_track->getD0(), - lc_track->getPhi(), - lc_track->getOmega(), - lc_track->getTanLambda(), - lc_track->getZ0()); - - // Set the track type - track->setType(lc_track->getType()); - - // Set the track fit chi^2 - track->setChi2(lc_track->getChi2()); - - // Set the position of the extrapolated track at the ECal face. The - // extrapolation uses the full 3D field map. - const EVENT::TrackState* track_state - = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); - double position_at_ecal[3] = { - track_state->getReferencePoint()[1], - track_state->getReferencePoint()[2], - track_state->getReferencePoint()[0] - }; - track->setPositionAtEcal(position_at_ecal); - // Get the collection of LCRelations between GBL kink data variables // (GBLKinkData) and the corresponding track. EVENT::LCCollection* gbl_kink_data = static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); - // Instantiate an LCRelation navigator which will allow faster access - // to GBLKinkData object - UTIL::LCRelationNavigator* gbl_kink_data_nav - = new UTIL::LCRelationNavigator(gbl_kink_data); - - // Get the list of GBLKinkData associated with the LCIO Track - EVENT::LCObjectVec gbl_kink_data_list - = gbl_kink_data_nav->getRelatedFromObjects(lc_track); - - // The container of GBLKinkData objects should only contain a - // single object. If not, throw an exception - if (gbl_kink_data_list.size() != 1) { - throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA_REL) - + " has the wrong data structure."); - } - - // Get the list GBLKinkData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* gbl_kink_datum - = static_cast(gbl_kink_data_list.at(0)); - - // Set the lambda and phi kink values - for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { - track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); - track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); - } - - delete gbl_kink_data_nav; - // Get the collection of LCRelations between track data variables // (TrackData) and the corresponding track. EVENT::LCCollection* track_data = static_cast( event->getLCCollection(Collections::TRACK_DATA_REL)); - - // Instantiate an LCRelation navigator which will allow faster access - // to TrackData objects - UTIL::LCRelationNavigator* track_data_nav - = new UTIL::LCRelationNavigator(track_data); - - // Get the list of TrackData associated with the LCIO Track - EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); - - // The container of TrackData objects should only contain a single - // object. If not, throw an exception. - if (track_data_list.size() == 1) { - - // Get the TrackData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); - - // Check that the TrackData data structure is correct. If it's - // not, throw a runtime exception. - if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 - || track_datum->getNInt() != 1) { - throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA) - + " has the wrong structure."); - } - - // Set the SvtTrack isolation values - for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { - track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); - } - - // Set the SvtTrack time - track->setTrackTime(track_datum->getFloatVal(0)); - - // Set the volume (top/bottom) in which the SvtTrack resides - track->setTrackVolume(track_datum->getIntVal(0)); - } - delete track_data_nav; + + // Add a track to the event + Track* track = utils::buildTrack(lc_track,gbl_kink_data,track_data); + // Get the collection of 3D hits associated with a LCIO Track EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); - + // Iterate through the collection of 3D hits (TrackerHit objects) // associated with a track, find the corresponding hits in the HPS // event and add references to the track - for (auto lc_tracker_hit : lc_tracker_hits) { - - TrackerHit* tracker_hit = new TrackerHit(); - // Get the position of the LCIO TrackerHit and set the position of - // the TrackerHit - double hit_position[3] = { - lc_tracker_hit->getPosition()[0], - lc_tracker_hit->getPosition()[1], - lc_tracker_hit->getPosition()[2] - }; - tracker_hit->setPosition(hit_position, true); - - // Set the covariance matrix of the SvtHit - tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); - - // Set the time of the SvtHit - tracker_hit->setTime(lc_tracker_hit->getTime()); - - // Set the charge of the SvtHit - tracker_hit->setCharge(lc_tracker_hit->getEDep()); - + + for (auto lc_tracker_hit : lc_tracker_hits) { - //Get the Raw content of the tracker hits - EVENT::LCObjectVec rawHits = lc_tracker_hit->getRawHits(); + TrackerHit* tracker_hit = utils::buildTrackerHit(static_cast(lc_tracker_hit)); - //Return 0 - //EVENT::LCObjectVec rawHits_navigated = tracker_hits_to_raw_nav->getRelatedToObjects(lc_tracker_hit); - - if (_debug) - std::cout<<"Raw Hit Size::"<< rawHits.size()< rawSvthitsOn3d; + utils::addRawInfoTo3dHit(tracker_hit,static_cast(lc_tracker_hit), + raw_svt_hit_fits,&rawSvthitsOn3d); - //TODO Change with iterator - for (unsigned int irh =0; irh(rawHits.at(irh)); - - EVENT::long64 value = - EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) | - ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 ); - decoder.setValue(value); - - - RawSvtHit* rawHit = new RawSvtHit(); - rawHit->setSystem(decoder["system"]); - rawHit->setBarrel(decoder["barrel"]); - rawHit->setLayer(decoder["layer"]); - rawHit->setModule(decoder["module"]); - rawHit->setSensor(decoder["sensor"]); - rawHit->setSide(decoder["side"]); - rawHit->setStrip(decoder["strip"]); - - // Extract ADC values for this hit - int hit_adcs[6] = { - (int)rawTracker_hit->getADCValues().at(0), - (int)rawTracker_hit->getADCValues().at(1), - (int)rawTracker_hit->getADCValues().at(2), - (int)rawTracker_hit->getADCValues().at(3), - (int)rawTracker_hit->getADCValues().at(4), - (int)rawTracker_hit->getADCValues().at(5)}; - - rawHit->setADCs(hit_adcs); + for (auto rhit : rawSvthitsOn3d) + rawhits_.push_back(rhit); - if (hasFits) - { - // Get the list of fit params associated with the raw tracker hit - EVENT::LCObjectVec rawTracker_hit_fits_list - = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); - - // Get the list SVTFittedRawTrackerHit GenericObject associated with the SVTRawTrackerHit - IMPL::LCGenericObjectImpl* hit_fit_param - = static_cast(rawTracker_hit_fits_list.at(0)); - - double fit_params[5] = { - (double)hit_fit_param->getDoubleVal(0), - (double)hit_fit_param->getDoubleVal(1), - (double)hit_fit_param->getDoubleVal(2), - (double)hit_fit_param->getDoubleVal(3), - (double)hit_fit_param->getDoubleVal(4) - }; - - rawHit->setFit(fit_params); - - } - - tracker_hit->addRawHit(rawHit); - rawhits_.push_back(rawHit); - if (_debug) - std::cout<<"RawHit ID:"<id()<getRawHits()->GetEntries()<getRawHits()->GetEntries()<addHit(tracker_hit); hits_.push_back(tracker_hit); diff --git a/processors/src/utilities.cxx b/processors/src/utilities.cxx index b9528b2a1..71ed07cbe 100644 --- a/processors/src/utilities.cxx +++ b/processors/src/utilities.cxx @@ -174,6 +174,9 @@ RawSvtHit* utils::buildRawHit(EVENT::TrackerRawData* rawTracker_hit, }; rawHit->setFit(fit_params); + if (rawTracker_hit_fits_nav) + delete rawTracker_hit_fits_nav; + rawTracker_hit_fits_nav = nullptr; }//raw svt hits return rawHit; @@ -216,7 +219,7 @@ TrackerHit* utils::buildTrackerHit(IMPL::TrackerHitImpl* lc_tracker_hit) { bool utils::addRawInfoTo3dHit(TrackerHit* tracker_hit, IMPL::TrackerHitImpl* lc_tracker_hit, - EVENT::LCCollection* raw_svt_fits) { + EVENT::LCCollection* raw_svt_fits, std::vector* rawHits) { if (!tracker_hit || !lc_tracker_hit) return false; @@ -228,12 +231,12 @@ bool utils::addRawInfoTo3dHit(TrackerHit* tracker_hit, int layer = -1; //Get the Raw content of the tracker hits - EVENT::LCObjectVec rawHits = lc_tracker_hit->getRawHits(); + EVENT::LCObjectVec lc_rawHits = lc_tracker_hit->getRawHits(); - for (unsigned int irh = 0 ; irh < rawHits.size(); ++irh) { + for (unsigned int irh = 0 ; irh < lc_rawHits.size(); ++irh) { //TODO useless to build all of it? - RawSvtHit* rawHit = buildRawHit(static_cast(rawHits.at(irh)),raw_svt_fits); + RawSvtHit* rawHit = buildRawHit(static_cast(lc_rawHits.at(irh)),raw_svt_fits); rawcharge += rawHit->getAmp(); int currentHitVolume = rawHit->getModule() % 2 ? 1 : 0; int currentHitLayer = (rawHit->getLayer() - 1 ) / 2; @@ -253,6 +256,8 @@ bool utils::addRawInfoTo3dHit(TrackerHit* tracker_hit, //TODO:: store only if asked tracker_hit->addRawHit(rawHit); + if (rawHits) + rawHits->push_back(rawHit); } From 4543e458e55da4b52c6ac9ef24fb8b702d53b2ac Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Tue, 1 Oct 2019 13:47:33 -0400 Subject: [PATCH 122/314] Initial commit --- .gitignore | 32 ++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..259148fa1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/README.md b/README.md new file mode 100644 index 000000000..b696515fe --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# hpstr +The HPS N-tuple analysis system. From 93bf80cc1a569c1a02bb01e7f745ff0307a15056 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 1 Oct 2019 12:15:48 -0700 Subject: [PATCH 123/314] Build svt frame tracker hits --- event/src/TrackerHit.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/event/src/TrackerHit.cxx b/event/src/TrackerHit.cxx index a96b0e8d6..237c927cc 100644 --- a/event/src/TrackerHit.cxx +++ b/event/src/TrackerHit.cxx @@ -21,13 +21,16 @@ void TrackerHit::Clear(Option_t* /* options */) { } void TrackerHit::setPosition(const double* position, bool rotate) { - + + //svt angle: it's already with minus sign. + float svtAngle = 30.5e-3; //Rotate the the input position automatically to match with the SVT tracker system if (rotate) { - x_ = position[1]; + //x_ = position[1]; y_ = position[2]; - z_ = position[1] * sin(30.5e-3) + position[0]*cos(30.5e-3); + z_ = position[1] * sin(svtAngle) + position[0]*cos(svtAngle); + x_ = position[1] * cos(svtAngle) - position[0]*sin(svtAngle); } else { x_ = position[0]; From 131dd7d2bf9646923d0ca1caf6a5a2a4fa063818 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 1 Oct 2019 15:16:47 -0700 Subject: [PATCH 124/314] Initial commit of plotting framework --- pyplot/ClustersOnTracks_simple.py | 80 +++++ pyplot/utilities.py | 572 ++++++++++++++++++++++++++++++ 2 files changed, 652 insertions(+) create mode 100755 pyplot/ClustersOnTracks_simple.py create mode 100755 pyplot/utilities.py diff --git a/pyplot/ClustersOnTracks_simple.py b/pyplot/ClustersOnTracks_simple.py new file mode 100755 index 000000000..bb0299ab3 --- /dev/null +++ b/pyplot/ClustersOnTracks_simple.py @@ -0,0 +1,80 @@ +from ROOT import * +import os +from utilities import * + + +SetStyle() + +#inFileList = ["hists_10494_bin5.root", +# "hists_10491_bin5.root", +# "hists_10492_bin5.root"] + + +path = "/Users/"+os.environ["USER"]+"/Dropbox/HPS/macros/hists/" +inFileList = [ + "projections_10710.root", + "projections_10711.root", + "projections_10712.root", + "projections_10713.root", + "projections_10714.root"] + + + +graphs = [] +colors = [kBlack, kRed, kBlue,kGreen+2,kOrange-2] + +inputFiles = [] +#legends = ["10494","10491: L0-1=70V, L2-3=270V, L4-6=180V","10492 L0-1=40V L2-3=100V L4-6=180V"] +legends = ["10710","10711","10712","10713","10714"] +outdir = "./Plots_BiasScan" + +if not os.path.exists(outdir): + os.makedirs(outdir) + +gROOT.SetBatch(1) + +for ifile in inFileList: + inf = TFile(path+"/"+ifile) + inputFiles.append(inf) + +for key in inputFiles[0].GetListOfKeys(): + print key.GetName() + + #TODO do it better + if "mean" not in key.GetName(): + continue + if "charge" not in key.GetName(): + continue + c = TCanvas() + leg = TLegend(0.3,0.4,0.7,0.15) + leg.SetBorderSize(0) + for i_f in range(0,len(inputFiles)): + graphs.append(inputFiles[i_f].Get(key.GetName())) + graphs[i_f].SetMarkerColor(colors[i_f]) + graphs[i_f].SetLineColor(colors[i_f]) + + if i_f == 0: + graphs[i_f].Draw("AP") + tYoff = graphs[i_f].GetYaxis().GetTitleOffset() + graphs[i_f].GetYaxis().SetTitleOffset(tYoff*0.75) + graphs[i_f].GetYaxis().SetRangeUser(400,1700) + labelSize = graphs[i_f].GetYaxis().GetLabelSize(); + graphs[i_f].GetYaxis().SetLabelSize(labelSize*0.7) + graphs[i_f].GetXaxis().SetLabelSize(labelSize*0.7) + graphs[i_f].GetYaxis().SetTitleSize(graphs[i_f].GetYaxis().GetTitleSize() * 0.6 ) + graphs[i_f].GetYaxis().SetTitleOffset(graphs[i_f].GetYaxis().GetTitleOffset() * 2.2 ) + graphs[i_f].GetXaxis().SetTitleSize(graphs[i_f].GetXaxis().GetTitleSize() * 0.6 ) + graphs[i_f].GetXaxis().SetTitleOffset(graphs[i_f].GetXaxis().GetTitleOffset() * 1 ) + graphs[i_f].GetXaxis().SetTitle("strip Position") + + else: + graphs[i_f].Draw("Psame") + entry = leg.AddEntry(legends[i_f],legends[i_f],"l") + entry.SetLineColor(colors[i_f]) + leg.Draw() + InsertText("Data 2019") + + + c.SaveAs(outdir+"/"+key.GetName()+".pdf") + + graphs = [] diff --git a/pyplot/utilities.py b/pyplot/utilities.py new file mode 100755 index 000000000..265da4008 --- /dev/null +++ b/pyplot/utilities.py @@ -0,0 +1,572 @@ +from ROOT import * +from array import array +import os,sys + +colors = [kBlack,kBlue+2,kRed+2,kGreen-1,kYellow+2,kRed+2,kAzure-2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3] +markers = [kFullCircle,kFullTriangleUp,kFullSquare,kOpenSquare,kOpenTriangleUp,kOpenCircle,kFullCircle,kOpenSquare,kFullSquare,kOpenTriangleUp,kOpenCircle,kFullCircle,kOpenSquare,kFullSquare,kOpenTriangleUp,kOpenCircle,kFullCircle,kOpenSquare,kFullSquare,kOpenTriangleUp,kOpenCircle,kFullCircle,kOpenSquare,kFullSquare,kOpenTriangleUp,kOpenCircle,kFullCircle,kOpenSquare,kFullSquare,kOpenTriangleUp] + + +#General configuration + +bottomFraction = 0.4 +bottomScale = 1./bottomFraction +topScale = 1./(1. - bottomFraction) +TProfile.Approximate(True) + + +def OptParsing(): + + from optparse import OptionParser + parser=OptionParser() + parser.add_option("--inputFile",dest="inputFile",help="inputFile",default="") + parser.add_option("--outdir",dest="outdir",help="outdir",default="") + parser.add_option("--indir",dest="indir",help="indir",default="") + parser.add_option("--runNumber",dest="runNumber",help="runNumber",default="") + parser.add_option("--Selections",dest="Selections",default="LooseTracks,LooseL2VTracks,LooseT2VTracks") + parser.add_option("--Legends",dest="Legends",default="Loose,Loose + L2V,Loose + T2V") + parser.add_option("--Legends2",dest="Legends2",default="Tracks,Tracks + Truth,Tracks_L2V,Tracks_L2V + Truth,Tracks_T2V,Tracks_T2V + Truth") + parser.add_option("--dataFile",dest="dataFile",default="") + (config,sys.argv[1:]) = parser.parse_args(sys.argv[1:]) + return config + + +#Get a plot from a directory+file name +def getPlot(loc,fin,plot): + print "Getting", plot + f = TFile.Open(loc+fin) + histo = f.Get(plot) + print histo + histo.SetDirectory(0) + + return histo + + +#Get a plot from a file +def getPlot(fullpath,plot): + print "Getting", plot + f = TFile.Open(fullpath) + histo = f.Get(plot) + print histo + histo.SetDirectory(0) + + return histo + + +#Pass a list of files +def MakeHistoListFromFiles(listOfFiles,path,histoName): + + histolist = [] + for infile in listOfFiles: + f = TFile.Open(infile) + print f + h = f.Get(path+histoName) + print path+histoName + print h + h.SetDirectory(0) + histolist.append(h) + return histolist + +#Pass a list of histogram names +def MakeHistoListFromSameFile(infile,path,histoNames): + histolist = [] + for h_name in histoNames: + print h_name + f = TFile.Open(infile) + print f + + h = f.Get(path+"/"+h_name) + print h + h.SetDirectory(0) + histolist.append(h) + return histolist + + +def InsertText(runNumber="",texts=[],line=0.87,xoffset=0.18,Atlas=True): + + + newline = 0.06 + + text = TLatex() + text.SetNDC() + text.SetTextFont(42) + text.SetTextSize(0.05) + text.SetTextColor(kBlack) + if (Atlas): + text.DrawLatex(xoffset,line,'#bf{#it{HPS} Internal}') + if runNumber: + line=line-newline + if "MC" in runNumber: + text.DrawLatex(xoffset,line,"MC Simulation") + else: + #text.DrawLatex(xoffset,line,"Run "+runNumber) + text.DrawLatex(xoffset,line,runNumber) + for iText in xrange(len(texts)): + if texts[iText]: + line=line-newline + text.DrawLatex(xoffset,line,texts[iText]) + + + +def SetStyle(): + gROOT.SetBatch(1) + + atlasStyle= TStyle("ATLAS","Atlas style") + + # use plain black on white colors + icol=0 + atlasStyle.SetFrameBorderMode(icol) + atlasStyle.SetCanvasBorderMode(icol) + atlasStyle.SetPadBorderMode(icol) + atlasStyle.SetPadColor(icol) + atlasStyle.SetCanvasColor(icol) + atlasStyle.SetStatColor(icol) +#atlasStyle.SetFillColor(icol) + +# set the paper & margin sizes + atlasStyle.SetPaperSize(20,26) + atlasStyle.SetPadTopMargin(0.05) + atlasStyle.SetPadRightMargin(0.05) + atlasStyle.SetPadBottomMargin(0.18) + atlasStyle.SetPadLeftMargin(0.14) + + # use large fonts +#font=72 + font=42 + tsize=0.07 + tzsize = 0.055 + atlasStyle.SetTextFont(font) + + + atlasStyle.SetTextSize(tsize) + atlasStyle.SetLabelFont(font,"x") + atlasStyle.SetTitleFont(font,"x") + atlasStyle.SetLabelFont(font,"y") + atlasStyle.SetTitleFont(font,"y") + atlasStyle.SetLabelFont(font,"z") + atlasStyle.SetTitleFont(font,"z") + + atlasStyle.SetLabelSize(tsize,"x") + atlasStyle.SetTitleSize(tsize,"x") + atlasStyle.SetLabelSize(tsize,"y") + atlasStyle.SetTitleSize(tsize,"y") + atlasStyle.SetLabelSize(tzsize,"z") + atlasStyle.SetTitleSize(tzsize,"z") + + atlasStyle.SetTitleOffset(0.8,"y") + atlasStyle.SetTitleOffset(1.3,"x") + + +#use bold lines and markers + #atlasStyle.SetMarkerStyle(20) + atlasStyle.SetMarkerSize(1.0) + atlasStyle.SetHistLineWidth(3) + atlasStyle.SetLineStyleString(2,"[12 12]") # postscript dashes + +#get rid of X error bars and y error bar caps +#atlasStyle.SetErrorX(0.001) + +#do not display any of the standard histogram decorations + atlasStyle.SetOptTitle(0) +#atlasStyle.SetOptStat(1111) + atlasStyle.SetOptStat(0) +#atlasStyle.SetOptFit(1111) + atlasStyle.SetOptFit(0) + +# put tick marks on top and RHS of plots + atlasStyle.SetPadTickX(1) + atlasStyle.SetPadTickY(1) + + gROOT.SetStyle("Plain") + +#gStyle.SetPadTickX(1) +#gStyle.SetPadTickY(1) + gROOT.SetStyle("ATLAS") + gROOT.ForceStyle() + gStyle.SetOptTitle(0) + gStyle.SetOptStat(0) + gStyle.SetOptFit(0) + + +# overwrite atlas styles + atlasStyle.SetPadLeftMargin(0.14) + atlasStyle.SetPadRightMargin(0.06) + atlasStyle.SetPadBottomMargin(0.11) + atlasStyle.SetPadTopMargin(0.05) + atlasStyle.SetFrameFillColor(0) + + NRGBs = 5; + NCont = 255; + + stops = array("d",[ 0.00, 0.34, 0.61, 0.84, 1.00 ]) + red = array("d",[ 0.00, 0.00, 0.87, 1.00, 0.51 ]) + green = array("d",[ 0.00, 0.81, 1.00, 0.20, 0.00 ]) + blue = array("d",[ 0.51, 1.00, 0.12, 0.00, 0.00 ]) + TColor.CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); + gStyle.SetNumberContours(NCont); + + +def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1,noErrors=False,RebinFactor=0,runNumber="",additionalText=[],RatioType="Alternate",LogX=False,LogY=False,RatioMin=0.25,RatioMax=1.75,WriteMean=False,Normalise=False): + + + if not os.path.exists(outdir): + os.mkdir(outdir) + + Xmin=0 + Xmax=1 + + can = TCanvas() + can.SetMargin(0,0,0,0) + top = TPad("top","top",0,0.42,1,1) + if LogX: + top.SetLogx(1) + bot.SetLogx(1) + if LogY: + top.SetLogy(1) + + + bot = TPad("bot","bot",0,0,1,0.38) + + + #----------Histogram------------# + + top.Draw() + top.SetBottomMargin(0) + top.SetTopMargin(gStyle.GetPadTopMargin()*topScale) + bot.Draw() + bot.SetTopMargin(0) + bot.SetBottomMargin(0.4) + top.cd() + plotsProperties=[] + + for ih in xrange(len(histos)): + + + + + if (Normalise): + histos[ih].Scale(1./histos[ih].Integral()) + histos[ih].GetYaxis().SetRangeUser(0.00001,histos[ih].GetMaximum()*15000) + + + histos[ih].SetMarkerColor(colors[ih]) + histos[ih].SetMarkerStyle(markers[ih]) + histos[ih].SetLineColor(colors[ih]) + + plotsProperties.append(("#mu=%.4f"%round(histos[ih].GetMean(),4))+(" #sigma=%.4f"%round(histos[ih].GetRMS(),4))) + + + if RebinFactor>0: + histos[ih].Rebin(RebinFactor) + + if ih==0: + histos[ih].GetYaxis().SetRangeUser(ymin,ymax) + if noErrors: + #histos[ih].GetXaxis().SetTextSize(0.045) + #histos[ih].GetYaxis().SetTextSize(0.045) + + + histos[ih].Draw("hist p") + + + else: + histos[ih].Draw() + if xtitle: + histos[ih].GetXaxis().SetTitle(xtitle) + if ytitle: + histos[ih].GetYaxis().SetTitle(ytitle) + else: + if noErrors: + histos[ih].Draw("same hist p") + else: + histos[ih].Draw("same") + + + InsertText(runNumber,additionalText,0.85) + if (WriteMean): + InsertText("",plotsProperties,0.85,0.6,False) + + + if len(legends)>0: + #print "building legend" + #upperY=0.6 + upperY=0.76 + linesep = 0.07 + lowerY=upperY - len(legends)* linesep + #minX = 0.51 + minX = 0.18 + maxX = minX+0.26 + leg=TLegend(minX,upperY,maxX,lowerY) + leg.SetBorderSize(0) + leg.SetFillColor(0) + leg.SetTextSize(0.04) + + + + for i_leg in xrange(len(legends)): + #print "Adding Entry",i_leg, legends[i_leg] + leg.AddEntry(histos[i_leg],legends[i_leg],"lpf") + + leg.Draw() + + + + #-------------Ratio---------------------# + + + bot.cd() + reference = histos[0].Clone("reference") + reference.GetYaxis().SetTitle("Ratio") + reference.GetYaxis().SetTitleSize(0.06) + reference.GetYaxis().SetRangeUser(RatioMin,RatioMax) + reference.GetYaxis().SetNdivisions(508) + reference.GetYaxis().SetDecimals(True) + reference.Draw("axis") + + + if (RatioType=="Sequential"): + + + for ih in range(1,len(histos)): + #ForRatio=None + #if type(histos[ih]) is TProfile: + # ForRatio = histos[ih].ProjectionX("ForRatio"+str(ih)+histos[ih].GetName()) + #else: + ForRatio = histos[ih].Clone("ForRatio"+str(ih)+histos[ih].GetName()) + + ForRatio.SetMaximum(100.) + ForRatio.Divide(reference) + ForRatio.DrawCopy("hist PX0 same") + + + elif (RatioType=="Alternate"): + + print "in alternate ratio" + for ih in range(1,len(histos),2): + + numerator=histos[ih].Clone("numerator") + #if isinstance(histos[ih],TProfile): + + # numerator=histos[ih].ProjectionX("numerator") + + #else: + + + + numerator.SetMaximum(100.) + numerator.Divide(histos[ih-1]) + numerator.DrawCopy("hist p same") + + + elif (RatioType=="Alternate2"): + print "in Alternate (h1 - h2) / h2" + + + numerator=histos[ih].Clone("numerator") + numerator.Add(histos[ih-1],-1) + numerator.SetMaximum(100.) + numerator.Divide(histos[ih-1]) + + numerator.DrawCopy("hist p same") + + + + line = TLine() + line.SetLineStyle(kDashed) + line.DrawLine(reference.GetXaxis().GetXmin(),1,reference.GetXaxis().GetXmax(),1) + + + can.SaveAs(outdir+"/"+name+oFext) + + +def DivideHistos(h1,h2): + for ibin in range(1,h1.GetNbinsX()+1): + if (h2.GetBinContent(ibin) == 0): + continue + h1.SetBinContent(ibin,h1.GetBinContent(ibin) / h2.GetBinContent(ibin)) + return h1 + + + +def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1,noErrors=False,RebinFactor=0,runNumber="",additionalText=[],LogX=False,WriteMean=False,multiLeg=False): + + + if not os.path.exists(outdir): + os.mkdir(outdir) + + + can = TCanvas() + if LogX: + can.SetLogx(1) + + means = [] + meansErr = [] + + + for ih in xrange(len(histos)): + + means.append(histos[ih].GetMean(2)) + meansErr.append(histos[ih].GetMeanError(2)) + + histos[ih].SetMarkerColor(colors[ih]) + histos[ih].SetMarkerStyle(markers[ih]) + histos[ih].SetLineColor(colors[ih]) + histos[ih].GetYaxis().SetRangeUser(ymin,ymax) + if ("pT" in name or "pt" in name): + histos[ih].GetXaxis().SetRangeUser(1.,20.) + #histos[ih].SetMarkerSize(0.5) + if RebinFactor>0: + histos[ih].Rebin(RebinFactor) + + + if ih==0: + if noErrors: + histos[ih].GetXaxis().SetTextSize(0.045) + histos[ih].GetYaxis().SetTextSize(0.045) + histos[ih].Draw("hist p") + + + else: + histos[ih].Draw() + if xtitle: + histos[ih].GetXaxis().SetTitle(xtitle) + if ytitle: + histos[ih].GetYaxis().SetTitle(ytitle) + else: + if noErrors: + histos[ih].Draw("same hist p") + else: + histos[ih].Draw("same") + + + + InsertText(runNumber,additionalText,0.52) + + if len(legends)>0: + #print "building legend" + upperY=0.6 + linesep = 0.10 + lowerY=upperY - len(legends)* linesep + minX = 0.51 + maxX = minX+0.33 + leg2 = None + + if len(legends) > 10: + leg2=TLegend(minX,upperY,maxX-0.02,lowerY) + leg2.SetBorderSize(0) + leg2.SetFillColor(0) + entry=leg2.AddEntry("Todo","To do","p") + entry.SetMarkerStyle(kOpenSquare) + + entry2=leg2.AddEntry("Todo","Todo","p") + entry2.SetMarkerStyle(kOpenCircle) + leg2.Draw() + + + + minX=0.87 + maxX=minX+0.12 + + + leg=TLegend(minX,upperY,maxX,lowerY) + leg.SetBorderSize(0) + leg.SetFillColor(0) + leg.SetTextSize(0.031) + + + + for i_leg in xrange(len(legends)): + + if not WriteMean: + print "Adding Entry",i_leg, legends[i_leg] + else: + print "Adding Entry",i_leg, legends[i_leg]+" #epsilon: " + str(round(means[i_leg],2)) + + + #leg.AddEntry(histos[i_leg],"#splitline{"+legends[i_leg] + "}{Average=" + str(round(means[i_leg]*100.,3))+"#pm"+str(round(meansErr[i_leg]*100,3))+"%}" ,"lpf") + #leg.AddEntry(histos[i_leg],legends[i_leg] + " Average=" + str(round(means[i_leg]*100.,3))+"#pm"+str(round(meansErr[i_leg]*100,3))+"%" ,"lpf") + if not multiLeg: + leg.AddEntry(histos[i_leg],legends[i_leg] + " Avg=" + str(round(means[i_leg]*100.,3))+"#pm"+str(round(meansErr[i_leg]*100,3))+"%" ,"lpf") + else: + leg.AddEntry(histos[i_leg],"#splitline{"+legends[i_leg] + "}{Avg=" + str(round(means[i_leg]*100.,3))+"#pm"+str(round(meansErr[i_leg]*100,3))+"%}" ,"lpf") + + leg.Draw() + + #BuildLegend(legends,can,histos,0.55,0.9,0.8,0.75) + + + can.SetBottomMargin(0.18) + can.SetLeftMargin(0.15) + + can.SaveAs(outdir+"/"+name+oFext) + + + +def Make2DRatio(name,outdir,histo1,histo2,xtitle="",ytitle="",ztitle="",runNumber="",legends=[]): + oFext=".pdf" + if not os.path.exists(outdir): + os.mkdir(outdir) + + ratio = histo1.Clone() + ratio.Divide(histo2) + + can = TCanvas() + can.SetRightMargin(0.2) + + ratio.GetZaxis().SetRangeUser(0.9,1.1) + ratio.GetXaxis().SetTitle(xtitle) + ratio.GetYaxis().SetTitle(ytitle) + ratio.GetZaxis().SetTitle(ztitle) + ratio.Draw("colz text") + + can.SaveAs(outdir+"/"+name+oFext) + + + +def Make2DPlots(name,outdir,histolist,xtitle="",ytitle="",ztitle="",text="",zmin="",zmax=""): + oFext=".pdf" + if not os.path.exists(outdir): + os.mkdir(outdir) + + for ih in range(0,len(histolist)): + can = TCanvas() + can.SetRightMargin(0.2) + + histolist[ih].GetZaxis().SetRangeUser(zmin,zmax) + histolist[ih].GetXaxis().SetTitle(xtitle) + histolist[ih].GetXaxis().SetTitleSize( + histolist[ih].GetXaxis().GetTitleSize()*0.7) + histolist[ih].GetXaxis().SetLabelSize( + histolist[ih].GetXaxis().GetLabelSize()*0.75) + histolist[ih].GetXaxis().SetTitleOffset( + histolist[ih].GetXaxis().GetTitleOffset()*0.8) + + histolist[ih].GetYaxis().SetTitleSize( + histolist[ih].GetYaxis().GetTitleSize()*0.7) + histolist[ih].GetYaxis().SetLabelSize( + histolist[ih].GetYaxis().GetLabelSize()*0.75) + histolist[ih].GetYaxis().SetTitleOffset( + histolist[ih].GetYaxis().GetTitleOffset()*1.7) + histolist[ih].GetYaxis().SetTitle(ytitle) + + + histolist[ih].Draw("colz") + + InsertText(text,"") + + print "saving..." + #if (len(legends) == len(histolist)): + can.SaveAs(outdir+"/"+name+oFext) + #else: + # print "ERROR: Not enough names for all the histos" + + +def Profile2DPlot(name,outdir,histolist,axis="X",xtitle="",ytitle="",ztitle="",runNumber="",legends=[],zmin="",zmax=""): + oFext=".pdf" + if not os.path.exists(outdir): + os.mkdir(outdir) + + p = None + + if (axis == "X"): + p = ProjectionX() + From 6085fd12dc91cd2ea8564f3bad4320ba7ef51058 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 1 Oct 2019 16:36:34 -0700 Subject: [PATCH 125/314] Added vertex class --- event/include/Collections.h | 28 ++++++++ event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 17 +++-- event/include/Vertex.h | 128 +++++++++++++++++++++++++++++++++++ event/src/Vertex.cxx | 43 ++++++++++++ 5 files changed, 210 insertions(+), 7 deletions(-) create mode 100644 event/include/Vertex.h create mode 100644 event/src/Vertex.cxx diff --git a/event/include/Collections.h b/event/include/Collections.h index fc189266c..5dfdf6a93 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -59,6 +59,34 @@ namespace Collections { /** Name of RF hits collection. */ constexpr const char* RF_HITS{"RFHits"}; + + /** There are three typical type of V0Candidates: BeamspotConstrained, TargetConstrained and Unconstrained */ + + /** Base name of the V0Candidates collection. */ + constexpr const char* V0CANDIDATES{"V0Candidates"}; + + /** Name of the BSC V0Candidates collection. */ + constexpr const char* BSC_V0CANDIDATES{"BeamspotConstrainedV0Candidates"}; + + /** Name of the TC V0Candidates collection. */ + constexpr const char* TC_V0CANDIDATES{"TargetConstrainedV0Candidates"}; + + /** Name of the UC V0Candidates collection. */ + constexpr const char* UC_V0CANDIDATES{"UnConstrainedV0Candidates"}; + + /** Name of the V0Vertices collection. */ + constexpr const char* V0VERTICES{"V0Vertices"}; + + /** Name of the BSC V0Vertices collection. */ + constexpr const char* BSC_V0VERTICES{"BeamspotConstrainedV0Vertices"}; + + /** Name of the TC V0Candidates collection. */ + constexpr const char* TC_V0Vertices{"TargetConstrainedV0Vertices"}; + + /** Name of the UC V0Candidates collection. */ + constexpr const char* UC_V0VERTICES{"UnConstrainedV0Vertices"}; + } #endif // _COLLECTION_H_ + diff --git a/event/include/EventDef.h b/event/include/EventDef.h index b534f1e82..18df5f162 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -5,5 +5,6 @@ #include "EventHeader.h" #include "Particle.h" #include "Track.h" +#include "Vertex.h" #include "TrackerHit.h" #include "RawSvtHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 35b9a7dcc..fb8778955 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -11,16 +11,19 @@ #pragma link C++ class EventHeader+; #pragma link C++ class Particle+; #pragma link C++ class Track+; +#pragma link C++ class Vertex+; #pragma link C++ class TrackerHit+; #pragma link C++ class RawSvtHit+; // This is to create the dictionary for stl containers -#pragma link C++ class vector +; -#pragma link C++ class vector +; -#pragma link C++ class vector +; -#pragma link C++ class vector +; -#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #pragma link C++ class vector +; -#pragma link C++ class vector +; -#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #endif diff --git a/event/include/Vertex.h b/event/include/Vertex.h new file mode 100644 index 000000000..f894a596f --- /dev/null +++ b/event/include/Vertex.h @@ -0,0 +1,128 @@ +/** + * @file Vertex.h + * @brief Class used to encapsulate Vertex information. + * @author PF, SLAC + */ + +#ifndef _VERTEX_H_ +#define _VERTEX_H_ + + +#include + +#include +#include +#include +#include + +//TODO make float/doubles accordingly. + +class Vertex : public TObject { + + public: + + /** Constructor */ + Vertex(); + + /** Destructor */ + ~Vertex(); + + /** Reset The Vertex object */ + void Clear(Option_t *option=""); + + /** + * Add a reference to a Track used for this vertex + * + * @param: A Track object + */ + + void addTrack(TObject* track); + + /** + * @return A reference to the tracks associated with this vertex + */ + TRefArray* getTracks() const {return tracks_;}; + + //TODO unify + void setChi2 (const double chi2) {chi2_ = chi2;}; + double getChi2 () const {return chi2_;}; + + void setX (const double x) {x_ = x;}; + double getX () const {return x_;}; + + void setY (const double y) {y_ = y;}; + double getY () const {return y_;}; + + void setZ (const double z) {z_ = z;}; + double getZ () const {return z_;}; + + void setPos (const TVector3& pos); + TVector3 getPos () const {return pos_;}; + + void setType (const std::string& type) {type_ = type;}; + std::string getType() const {return type_;}; + + bool vxTracksAvailable() const ; + + int nTracks() const; + + //Returns the covariance matrix as a simple vector of values + const std::vector& covariance () const {return covariance_;}; + + //Sets the covariance matrix as a simple vector of values + void setCovariance( const std::vector* vec); + + void setNdf (const double ndf) {ndf_ = ndf;}; + double getNdf () const {return ndf_;}; + + void setProbability(const float probability) {probability_ = probability;}; + float getProbability () const {return probability_;}; + + //sets the id + void setID (const int id) {id_=id;}; + + //gets the ID + int getID () {return id_;} + + //TODO - 2 tracks only? + double getP1X () const {return p1x_;}; + double getP1Y () const {return p1y_;}; + double getP1Z () const {return p1z_;}; + TVector3 getP1 () const {return p1_;}; + + double getP2X () const {return p2x_;}; + double getP2Y () const {return p2y_;}; + double getP2Z () const {return p2z_;}; + TVector3 getP2 () const {return p2_;}; + + private: + + double chi2_{-999}; + double x_{-999}; + double y_{-999}; + double z_{-999}; + int ndf_{-999}; + TVector3 pos_,p1_,p2_; + int ntracks_; + + double p1x_{-999}; + double p2x_{-999}; + + double p1y_{-999}; + double p2y_{-999}; + + double p1z_{-999}; + double p2z_{-999}; + + + std::vector covariance_{}; + float probability_{-999}; + int id_; + std::string type_{""}; + TRefArray* tracks_; + + ClassDef(Vertex,1); + +}; // Vertex + +#endif // __VERTEX_H__ diff --git a/event/src/Vertex.cxx b/event/src/Vertex.cxx new file mode 100644 index 000000000..1a67ac4bd --- /dev/null +++ b/event/src/Vertex.cxx @@ -0,0 +1,43 @@ +/** + * @file Vertex.h + * @brief Class used to encapsulate vertex information. + * @author PF, SLAC + */ + +#include "Vertex.h" + +ClassImp(Vertex) + +Vertex::Vertex() +: TObject() { +} + +Vertex::~Vertex() { + Clear(); + delete tracks_; +} + +void Vertex::Clear(Option_t *option) { + TObject::Clear(); + if (tracks_) + tracks_->Delete(); + pos_.Clear(); + p1_.Clear(); + p2_.Clear(); + ntracks_ = 0; + x_ = -999.; + y_ = -999.; + z_ = -999.; +} + +bool Vertex::vxTracksAvailable() const { + + if (tracks_) + return true; + + return false; +} + +void Vertex::setCovariance ( const std::vector* vec) { +} + From 53d004bc98360e69765f70abebaa8ce882c01259 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 1 Oct 2019 19:14:22 -0700 Subject: [PATCH 126/314] Initial changes to trigger data parsing --- event/include/Collections.h | 2 +- event/src/TriggerData.cxx | 78 ++++++++++++++++++----- processors/src/EventProcessor.cxx | 39 +++++------- pyplot/ClustersOnTracks_simple.py | 3 +- pyplot/utilities.py | 100 +++++++++++++++--------------- setup.sh | 2 +- 6 files changed, 131 insertions(+), 93 deletions(-) diff --git a/event/include/Collections.h b/event/include/Collections.h index fc189266c..0f178d22e 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -55,7 +55,7 @@ namespace Collections { constexpr const char* EVENT_HEADERS{"EventHeader"}; /** Name of trigger bank collection. */ - constexpr const char* TRIGGER_BANK{"TriggerBank"}; + constexpr const char* TRIGGER_BANK{"VTPBank"}; /** Name of RF hits collection. */ constexpr const char* RF_HITS{"RFHits"}; diff --git a/event/src/TriggerData.cxx b/event/src/TriggerData.cxx index 72a74f0e7..23032e686 100644 --- a/event/src/TriggerData.cxx +++ b/event/src/TriggerData.cxx @@ -10,22 +10,66 @@ TriggerData::TriggerData(EVENT::LCGenericObject* trigger_data) { this->parseTriggerData(trigger_data); } -void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) { +void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) +{ + //std::cout << trigger_data->getNInt() << " VTP words" << std::endl; + for(int i = 0; i < trigger_data->getNInt(); i++) + { + int trigger_data_int = trigger_data->getIntVal(i); + if(!(trigger_data_int & 1<<31)) continue; + int type = (trigger_data_int>>27)&0x0F; + int subtype = -1; + switch (type) + { + case 0: // Block Header + //std::cout << i << "VTP Block Header Word" << std::endl; + break; + case 1: // Block Tail + //std::cout << i << "VTP Block Tail Word" << std::endl; + break; + case 2: // Event Header + //std::cout << i << "VTP Event Header Word" << std::endl; + break; + case 3: // Trigger time + time_stamp_ = (trigger_data_int & 0x00FFFFFF) + ((trigger_data->getIntVal(i+1)& 0x00FFFFFF )<<24); + i++; + break; + case 12: // Expansion type + subtype = (trigger_data_int>>23)&0x0F; + switch(subtype){ + case 2: // HPS Cluster + //std::cout << i << "VTP Cluster Word" << std::endl; + break; + case 3: // HPS Single Cluster + //std::cout << i << "VTP Single Cluster Word" << std::endl; + break; + case 4: // HPS Pair Trigger + //std::cout << i << "VTP Pair Trigger Word" << std::endl; + break; + case 5: // HPS Calibration Trigger + //std::cout << i << "VTP Calibration Trigger Word: " << trigger_data_int << std::endl; + break; + case 6: // HPS Cluster Multiplicity Trigger + //std::cout << i << "VTP Cluster Multiplicity Trigger Word" << std::endl; + break; + case 7: // HPS FEE Trigger + //std::cout << i << "VTP FEE Trigger Word" << std::endl; + break; + default: + //std::cout << "At " << i << " invalid HPS type: " << type << " subtype: " << subtype << std::endl; + } - int trigger_data_int = trigger_data->getIntVal(1); - single0_ = ((trigger_data_int >> 24) & 1) == 1; - single1_ = ((trigger_data_int >> 25) & 1) == 1; - pair0_ = ((trigger_data_int >> 26) & 1) == 1; - pair1_ = ((trigger_data_int >> 27) & 1) == 1; - pulser_ = ((trigger_data_int >> 29) & 1) == 1; - - trigger_data_int = trigger_data->getIntVal(3); - long w1 = trigger_data_int & 0xffffffffL; - trigger_data_int = trigger_data->getIntVal(4); - long w2 = trigger_data_int & 0xffffffffL; - - long timelo = w1; - long timehi = (w2 & 0xffff) << 32; - - time_stamp_ = 4 * (timelo + timehi); + break; + case 14: + //std::cout << i << "VTP data type not valid: " << type << std::endl; + break; + default: + //std::cout << i << "I was not expecting a VTP data type of " << type << std::endl; + } + single0_ = 0; + single1_ = 0; + pair0_ = 0; + pair1_ = 0; + pulser_ = 0; + } } diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index 2fff9cdb6..da5014a98 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -61,24 +61,17 @@ bool EventProcessor::process(IEvent* ievent) { EVENT::LCCollection* trigger_data = static_cast(event->getLCCollection(Collections::TRIGGER_BANK)); - for (int itrigger = 0; itrigger < trigger_data->getNumberOfElements(); ++itrigger) { - - EVENT::LCGenericObject* trigger_datum - = static_cast(trigger_data->getElementAt(itrigger)); - - if (trigger_datum->getIntVal(0) == 0xe10a) { - - TriggerData* tdata = new TriggerData(trigger_datum); - header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); - header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); - header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); - header.setPair1Trigger(static_cast(tdata->isPair1Trigger())); - header.setPulserTrigger(static_cast(tdata->isPulserTrigger())); - - delete tdata; - break; - } - } + EVENT::LCGenericObject* trigger_datum + = static_cast(trigger_data->getElementAt(0)); + + TriggerData* tdata = new TriggerData(trigger_datum); + header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); + header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); + header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); + header.setPair1Trigger(static_cast(tdata->isPair1Trigger())); + header.setPulserTrigger(static_cast(tdata->isPulserTrigger())); + + delete tdata; } catch(EVENT::DataNotAvailableException e) { // It's fine if the event doesn't have a trigger bank. } @@ -97,18 +90,18 @@ bool EventProcessor::process(IEvent* ievent) { // Loop over all the RF hits in the event and write them to the DST for (int ihit = 0; ihit < rf_hits->getNumberOfElements(); ++ihit) { - + // Get the RF hit from the event EVENT::LCGenericObject* rf_hit = static_cast(rf_hits->getElementAt(ihit)); - + // An RFHit GenericObject should only have two RF times if (rf_hit->getNDouble() != 2) { throw std::runtime_error("[ EventProcessor ]: The collection " - + static_cast(Collections::RF_HITS) - + " has the wrong structure."); + + static_cast(Collections::RF_HITS) + + " has the wrong structure."); } - + // Write the RF times to the event for (int ichannel = 0; ichannel < rf_hit->getNDouble(); ++ichannel) { header.setRfTime(ichannel, rf_hit->getDoubleVal(ichannel)); diff --git a/pyplot/ClustersOnTracks_simple.py b/pyplot/ClustersOnTracks_simple.py index bb0299ab3..82aadeb14 100755 --- a/pyplot/ClustersOnTracks_simple.py +++ b/pyplot/ClustersOnTracks_simple.py @@ -10,7 +10,8 @@ # "hists_10492_bin5.root"] -path = "/Users/"+os.environ["USER"]+"/Dropbox/HPS/macros/hists/" +#path = "/Users/"+os.environ["USER"]+"/Dropbox/HPS/macros/hists/" +path = "/data/run/hists/" inFileList = [ "projections_10710.root", "projections_10711.root", diff --git a/pyplot/utilities.py b/pyplot/utilities.py index 265da4008..9b7f0f424 100755 --- a/pyplot/utilities.py +++ b/pyplot/utilities.py @@ -81,7 +81,7 @@ def MakeHistoListFromSameFile(infile,path,histoNames): return histolist -def InsertText(runNumber="",texts=[],line=0.87,xoffset=0.18,Atlas=True): +def InsertText(runNumber="",texts=[],line=0.87,xoffset=0.18,Hps=True): newline = 0.06 @@ -91,7 +91,7 @@ def InsertText(runNumber="",texts=[],line=0.87,xoffset=0.18,Atlas=True): text.SetTextFont(42) text.SetTextSize(0.05) text.SetTextColor(kBlack) - if (Atlas): + if (Hps): text.DrawLatex(xoffset,line,'#bf{#it{HPS} Internal}') if runNumber: line=line-newline @@ -110,89 +110,89 @@ def InsertText(runNumber="",texts=[],line=0.87,xoffset=0.18,Atlas=True): def SetStyle(): gROOT.SetBatch(1) - atlasStyle= TStyle("ATLAS","Atlas style") + hpsStyle= TStyle("HPS","HPS style") # use plain black on white colors icol=0 - atlasStyle.SetFrameBorderMode(icol) - atlasStyle.SetCanvasBorderMode(icol) - atlasStyle.SetPadBorderMode(icol) - atlasStyle.SetPadColor(icol) - atlasStyle.SetCanvasColor(icol) - atlasStyle.SetStatColor(icol) -#atlasStyle.SetFillColor(icol) + hpsStyle.SetFrameBorderMode(icol) + hpsStyle.SetCanvasBorderMode(icol) + hpsStyle.SetPadBorderMode(icol) + hpsStyle.SetPadColor(icol) + hpsStyle.SetCanvasColor(icol) + hpsStyle.SetStatColor(icol) +#hpsStyle.SetFillColor(icol) # set the paper & margin sizes - atlasStyle.SetPaperSize(20,26) - atlasStyle.SetPadTopMargin(0.05) - atlasStyle.SetPadRightMargin(0.05) - atlasStyle.SetPadBottomMargin(0.18) - atlasStyle.SetPadLeftMargin(0.14) + hpsStyle.SetPaperSize(20,26) + hpsStyle.SetPadTopMargin(0.05) + hpsStyle.SetPadRightMargin(0.05) + hpsStyle.SetPadBottomMargin(0.18) + hpsStyle.SetPadLeftMargin(0.14) # use large fonts #font=72 font=42 tsize=0.07 tzsize = 0.055 - atlasStyle.SetTextFont(font) + hpsStyle.SetTextFont(font) - atlasStyle.SetTextSize(tsize) - atlasStyle.SetLabelFont(font,"x") - atlasStyle.SetTitleFont(font,"x") - atlasStyle.SetLabelFont(font,"y") - atlasStyle.SetTitleFont(font,"y") - atlasStyle.SetLabelFont(font,"z") - atlasStyle.SetTitleFont(font,"z") + hpsStyle.SetTextSize(tsize) + hpsStyle.SetLabelFont(font,"x") + hpsStyle.SetTitleFont(font,"x") + hpsStyle.SetLabelFont(font,"y") + hpsStyle.SetTitleFont(font,"y") + hpsStyle.SetLabelFont(font,"z") + hpsStyle.SetTitleFont(font,"z") - atlasStyle.SetLabelSize(tsize,"x") - atlasStyle.SetTitleSize(tsize,"x") - atlasStyle.SetLabelSize(tsize,"y") - atlasStyle.SetTitleSize(tsize,"y") - atlasStyle.SetLabelSize(tzsize,"z") - atlasStyle.SetTitleSize(tzsize,"z") + hpsStyle.SetLabelSize(tsize,"x") + hpsStyle.SetTitleSize(tsize,"x") + hpsStyle.SetLabelSize(tsize,"y") + hpsStyle.SetTitleSize(tsize,"y") + hpsStyle.SetLabelSize(tzsize,"z") + hpsStyle.SetTitleSize(tzsize,"z") - atlasStyle.SetTitleOffset(0.8,"y") - atlasStyle.SetTitleOffset(1.3,"x") + hpsStyle.SetTitleOffset(0.8,"y") + hpsStyle.SetTitleOffset(1.3,"x") #use bold lines and markers - #atlasStyle.SetMarkerStyle(20) - atlasStyle.SetMarkerSize(1.0) - atlasStyle.SetHistLineWidth(3) - atlasStyle.SetLineStyleString(2,"[12 12]") # postscript dashes + #hpsStyle.SetMarkerStyle(20) + hpsStyle.SetMarkerSize(1.0) + hpsStyle.SetHistLineWidth(3) + hpsStyle.SetLineStyleString(2,"[12 12]") # postscript dashes #get rid of X error bars and y error bar caps -#atlasStyle.SetErrorX(0.001) +#hpsStyle.SetErrorX(0.001) #do not display any of the standard histogram decorations - atlasStyle.SetOptTitle(0) -#atlasStyle.SetOptStat(1111) - atlasStyle.SetOptStat(0) -#atlasStyle.SetOptFit(1111) - atlasStyle.SetOptFit(0) + hpsStyle.SetOptTitle(0) +#hpsStyle.SetOptStat(1111) + hpsStyle.SetOptStat(0) +#hpsStyle.SetOptFit(1111) + hpsStyle.SetOptFit(0) # put tick marks on top and RHS of plots - atlasStyle.SetPadTickX(1) - atlasStyle.SetPadTickY(1) + hpsStyle.SetPadTickX(1) + hpsStyle.SetPadTickY(1) gROOT.SetStyle("Plain") #gStyle.SetPadTickX(1) #gStyle.SetPadTickY(1) - gROOT.SetStyle("ATLAS") + gROOT.SetStyle("HPS") gROOT.ForceStyle() gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetOptFit(0) -# overwrite atlas styles - atlasStyle.SetPadLeftMargin(0.14) - atlasStyle.SetPadRightMargin(0.06) - atlasStyle.SetPadBottomMargin(0.11) - atlasStyle.SetPadTopMargin(0.05) - atlasStyle.SetFrameFillColor(0) +# overwrite hps styles + hpsStyle.SetPadLeftMargin(0.14) + hpsStyle.SetPadRightMargin(0.06) + hpsStyle.SetPadBottomMargin(0.11) + hpsStyle.SetPadTopMargin(0.05) + hpsStyle.SetFrameFillColor(0) NRGBs = 5; NCont = 255; diff --git a/setup.sh b/setup.sh index a0af3df02..b61571a77 100644 --- a/setup.sh +++ b/setup.sh @@ -1,6 +1,6 @@ #!/bin/bash #export PYTHONPATH=/data/src/hpstr/processing/python:$PYTHONPATH -export PYTHONPATH=/data/src/hpstr/install/lib/python:$PYTHONPATH +export PYTHONPATH=/data/src/hpstr/pyplot:/data/src/hpstr/install/lib/python:$PYTHONPATH export PATH=/data/src/hpstr/install/bin:$PATH export LD_LIBRARY_PATH=/data/src/hpstr/install/lib:$LD_LIBRARY_PATH From 08493bbc05d9fb886c094b406eb81be9aafb7bdc Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 1 Oct 2019 19:23:09 -0700 Subject: [PATCH 127/314] Finer binning --- analysis/src/ClusterHistos.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx index fc98abb8d..31900bf74 100644 --- a/analysis/src/ClusterHistos.cxx +++ b/analysis/src/ClusterHistos.cxx @@ -85,14 +85,14 @@ void ClusterHistos::Define2DHistos() { // location of the hits histos2d[m_name+"_gy_L0T_vs_gx"] = plot2D(m_name+"_gy_L0T_vs_gx", - "Global X [mm] ",80,-20,20, - "Global Y [mm]",100,0,5); + "Global X [mm] ",400,-20,20, + "Global Y [mm]",200,0,5); histos2d[m_name+"_gy_L0B_vs_gx"] = plot2D(m_name+"_gy_L0B_vs_gx", - "Global X [mm] ",80,-20,20, - "Global Y [mm]",100,0,5); + "Global X [mm] ",400,-20,20, + "Global Y [mm]",200,0,5); From 84919b4c732a84df3415d2275de13276588bfb14 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 1 Oct 2019 19:35:52 -0700 Subject: [PATCH 128/314] Small bug fix --- event/src/TriggerData.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/event/src/TriggerData.cxx b/event/src/TriggerData.cxx index 23032e686..24165f914 100644 --- a/event/src/TriggerData.cxx +++ b/event/src/TriggerData.cxx @@ -57,6 +57,7 @@ void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) break; default: //std::cout << "At " << i << " invalid HPS type: " << type << " subtype: " << subtype << std::endl; + break; } break; @@ -65,6 +66,7 @@ void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) break; default: //std::cout << i << "I was not expecting a VTP data type of " << type << std::endl; + break; } single0_ = 0; single1_ = 0; From 244078f8772eb2513a28a10a73e87b7cb2daf9f3 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 1 Oct 2019 19:42:20 -0700 Subject: [PATCH 129/314] Vertex class updates. Utilities for building vertex updates --- event/include/Vertex.h | 29 +++++++++++++++++++++++++---- event/src/Vertex.cxx | 23 ++++++++++++++++++++++- processors/include/utilities.h | 7 +++++++ processors/src/utilities.cxx | 26 ++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/event/include/Vertex.h b/event/include/Vertex.h index f894a596f..82664c773 100644 --- a/event/include/Vertex.h +++ b/event/include/Vertex.h @@ -55,10 +55,20 @@ class Vertex : public TObject { void setZ (const double z) {z_ = z;}; double getZ () const {return z_;}; - + + /** Set the position of the vertex. If rotate is set to true, then position is defined in svt coordinates */ + void setPos (const float* pos, bool rotate = false); + + /** Set the position from a TVector */ void setPos (const TVector3& pos); TVector3 getPos () const {return pos_;}; + /** Vertex parameters depend on LCIO files. + * The available parameters are invMass, p1X, p2Y, p2X, p1Z, p2Z, p1Y, invMassError + */ + + void setVtxParameters(float* parameters); + void setType (const std::string& type) {type_ = type;}; std::string getType() const {return type_;}; @@ -66,11 +76,16 @@ class Vertex : public TObject { int nTracks() const; - //Returns the covariance matrix as a simple vector of values + /** Returns the covariance matrix as a simple vector of values */ const std::vector& covariance () const {return covariance_;}; - //Sets the covariance matrix as a simple vector of values + /** Sets the covariance matrix as a simple vector of values + * Covariance matrix of the position (stored as lower triangle matrix, i.e. + * cov(xx),cov(y,x),cov(y,y) ). + */ + void setCovariance( const std::vector* vec); + void setNdf (const double ndf) {ndf_ = ndf;}; double getNdf () const {return ndf_;}; @@ -94,7 +109,10 @@ class Vertex : public TObject { double getP2Y () const {return p2y_;}; double getP2Z () const {return p2z_;}; TVector3 getP2 () const {return p2_;}; - + + float getInvMass () const {return invM_;}; + float getInvMassErr () const {return invMerr_;}; + private: double chi2_{-999}; @@ -113,6 +131,9 @@ class Vertex : public TObject { double p1z_{-999}; double p2z_{-999}; + + float invM_{-999}; + float invMerr_{-999}; std::vector covariance_{}; diff --git a/event/src/Vertex.cxx b/event/src/Vertex.cxx index 1a67ac4bd..1d417ca26 100644 --- a/event/src/Vertex.cxx +++ b/event/src/Vertex.cxx @@ -38,6 +38,27 @@ bool Vertex::vxTracksAvailable() const { return false; } -void Vertex::setCovariance ( const std::vector* vec) { +int Vertex::nTracks() const { + if (vxTracksAvailable()) + return tracks_->GetEntries(); + return -1; } +void Vertex::setCovariance( const std::vector* vec){ + covariance_ = *vec; +} + +void Vertex::setPos(const float* pos, bool rotate) { + float svtAngle = 30.5e-3; + if (rotate) { + y_ = pos[2]; + z_ = pos[1]*sin(svtAngle) + pos[0]*cos(svtAngle); + x_ = pos[0]*cos(svtAngle) - pos[0]*sin(svtAngle); + } + else { + x_ = pos[1]; + y_ = pos[2]; + z_ = pos[0]; + } + +} diff --git a/processors/include/utilities.h b/processors/include/utilities.h index 51060e631..f936c752d 100644 --- a/processors/include/utilities.h +++ b/processors/include/utilities.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -19,11 +20,17 @@ #include "Collections.h" #include "Processor.h" #include "Track.h" +#include "Vertex.h" #include "RawSvtHit.h" #include "Event.h" #include "TrackerHit.h" namespace utils { + + + bool hasCollection(EVENT::LCEvent* lc_event,const std::string& collection); + + Vertex* buildVertex(EVENT::Vertex* lc_vertex); Track* buildTrack(EVENT::Track* lc_track, EVENT::LCCollection* gbl_kink_data, diff --git a/processors/src/utilities.cxx b/processors/src/utilities.cxx index 71ed07cbe..b65356368 100644 --- a/processors/src/utilities.cxx +++ b/processors/src/utilities.cxx @@ -13,6 +13,32 @@ void utils::buildTrackCollection(std::vector& tracks, */ + +bool utils::hasCollection(EVENT::LCEvent* lc_event,const std::string& collection) { + + if (!lc_event || collection.empty()) + return false; + + auto evColls = lc_event->getCollectionNames(); + auto it = std::find(evColls->begin(),evColls->end(), collection); + if (it!=evColls->end()) + return true; + return false; +} + + +Vertex* utils::buildVertex(EVENT::Vertex* lc_vertex) { + + if (!lc_vertex) + return nullptr; + + Vertex* vertex = new Vertex(); + vertex->setChi2 (lc_vertex->getChi2()); + vertex->setProbability(lc_vertex->getProbability()); + + return vertex; +} + Track* utils::buildTrack(EVENT::Track* lc_track, EVENT::LCCollection* gbl_kink_data, EVENT::LCCollection* track_data) { From de4048bfb4a5a89fc4d0014e8832e718b30e8ae7 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Tue, 1 Oct 2019 19:46:09 -0700 Subject: [PATCH 130/314] Change permissions on files --- event/src/Vertex.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/event/src/Vertex.cxx b/event/src/Vertex.cxx index 1d417ca26..d7e100e46 100644 --- a/event/src/Vertex.cxx +++ b/event/src/Vertex.cxx @@ -59,6 +59,5 @@ void Vertex::setPos(const float* pos, bool rotate) { x_ = pos[1]; y_ = pos[2]; z_ = pos[0]; - } - + } } From 1ecf775c4c40b64aa5d01a99346518ec32eef2d0 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Wed, 2 Oct 2019 15:29:49 -0700 Subject: [PATCH 131/314] Update event/TriggerData to be based on vtp and ts data --- event/include/Collections.h | 8 ++++++- event/include/TriggerData.h | 4 ++-- event/src/TriggerData.cxx | 35 ++++++++++++++++++------------- processors/src/EventProcessor.cxx | 16 +++++++++----- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/event/include/Collections.h b/event/include/Collections.h index b962d8647..1ea810107 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -55,7 +55,13 @@ namespace Collections { constexpr const char* EVENT_HEADERS{"EventHeader"}; /** Name of trigger bank collection. */ - constexpr const char* TRIGGER_BANK{"VTPBank"}; + constexpr const char* TRIGGER_BANK{"TriggerBank"}; + + /** Name of vtp (JLab VME Trigger Processor) bank collection. */ + constexpr const char* VTP_BANK{"VTPBank"}; + + /** Name of trigger supervisor bank collection. */ + constexpr const char* TS_BANK{"TSBank"}; /** Name of RF hits collection. */ constexpr const char* RF_HITS{"RFHits"}; diff --git a/event/include/TriggerData.h b/event/include/TriggerData.h index 0ca7fc741..7efd08f4d 100644 --- a/event/include/TriggerData.h +++ b/event/include/TriggerData.h @@ -22,7 +22,7 @@ class TriggerData { * @param trigger_data : The LCGenericObeject that is being used to * store the data from the TI */ - TriggerData(EVENT::LCGenericObject* trigger_data); + TriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data); /** @return The trigger time. */ double getTime() const { return time_stamp_; }; @@ -45,7 +45,7 @@ class TriggerData { private: /** Private method used to decode all trigger information. */ - void parseTriggerData(EVENT::LCGenericObject* trigger_data); + void parseTriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data); /** Trigger time stamp. */ long time_stamp_{-9999}; diff --git a/event/src/TriggerData.cxx b/event/src/TriggerData.cxx index 24165f914..dc21f6903 100644 --- a/event/src/TriggerData.cxx +++ b/event/src/TriggerData.cxx @@ -6,18 +6,18 @@ #include "TriggerData.h" -TriggerData::TriggerData(EVENT::LCGenericObject* trigger_data) { - this->parseTriggerData(trigger_data); +TriggerData::TriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data) { + this->parseTriggerData(vtp_data, ts_data); } -void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) +void TriggerData::parseTriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data) { //std::cout << trigger_data->getNInt() << " VTP words" << std::endl; - for(int i = 0; i < trigger_data->getNInt(); i++) + for(int i = 0; i < vtp_data->getNInt(); i++) { - int trigger_data_int = trigger_data->getIntVal(i); - if(!(trigger_data_int & 1<<31)) continue; - int type = (trigger_data_int>>27)&0x0F; + int vtp_data_int = vtp_data->getIntVal(i); + if(!(vtp_data_int & 1<<31)) continue; + int type = (vtp_data_int>>27)&0x0F; int subtype = -1; switch (type) { @@ -31,11 +31,11 @@ void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) //std::cout << i << "VTP Event Header Word" << std::endl; break; case 3: // Trigger time - time_stamp_ = (trigger_data_int & 0x00FFFFFF) + ((trigger_data->getIntVal(i+1)& 0x00FFFFFF )<<24); + time_stamp_ = (vtp_data_int & 0x00FFFFFF) + ((vtp_data->getIntVal(i+1)& 0x00FFFFFF )<<24); i++; break; case 12: // Expansion type - subtype = (trigger_data_int>>23)&0x0F; + subtype = (vtp_data_int>>23)&0x0F; switch(subtype){ case 2: // HPS Cluster //std::cout << i << "VTP Cluster Word" << std::endl; @@ -68,10 +68,17 @@ void TriggerData::parseTriggerData(EVENT::LCGenericObject* trigger_data) //std::cout << i << "I was not expecting a VTP data type of " << type << std::endl; break; } - single0_ = 0; - single1_ = 0; - pair0_ = 0; - pair1_ = 0; - pulser_ = 0; + + } + + //Parse data from trigger supervisor + for(int i = 0; i < ts_data->getNInt(); i++) + { + break; } + single0_ = 0; + single1_ = 0; + pair0_ = 0; + pair1_ = 0; + pulser_ = 0; } diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index da5014a98..986a1e4c6 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -58,13 +58,19 @@ bool EventProcessor::process(IEvent* ievent) { header.setSvtEventHeaderState(lc_event->getParameters().getIntVal("svt_event_header_good")); try { - EVENT::LCCollection* trigger_data - = static_cast(event->getLCCollection(Collections::TRIGGER_BANK)); + EVENT::LCCollection* vtp_data + = static_cast(event->getLCCollection(Collections::VTP_BANK)); - EVENT::LCGenericObject* trigger_datum - = static_cast(trigger_data->getElementAt(0)); + EVENT::LCGenericObject* vtp_datum + = static_cast(vtp_data->getElementAt(0)); - TriggerData* tdata = new TriggerData(trigger_datum); + EVENT::LCCollection* ts_data + = static_cast(event->getLCCollection(Collections::TS_BANK)); + + EVENT::LCGenericObject* ts_datum + = static_cast(ts_data->getElementAt(0)); + + TriggerData* tdata = new TriggerData(vtp_datum, ts_datum); header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); From e9d8788df1b7ff7c8bc60705e481627916068db3 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Fri, 4 Oct 2019 11:17:09 -0700 Subject: [PATCH 132/314] VTP data added to TriggerData --- event/include/EventDef.h | 2 + event/include/EventHeader.h | 23 +++ event/include/EventLinkDef.h | 2 + event/include/Track.h | 148 ++++++++--------- event/include/TriggerData.h | 42 ++--- event/include/VTPData.h | 157 ++++++++++++++++++ event/src/TriggerData.cxx | 70 +------- event/src/VTPData.cxx | 85 ++++++++++ processors/src/EventProcessor.cxx | 15 +- processors/src/TrackingProcessor.cxx | 228 +++++++++++++-------------- 10 files changed, 476 insertions(+), 296 deletions(-) create mode 100644 event/include/VTPData.h create mode 100644 event/src/VTPData.cxx diff --git a/event/include/EventDef.h b/event/include/EventDef.h index 18df5f162..5635a65d9 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -3,6 +3,8 @@ #include "CalHit.h" #include "Event.h" #include "EventHeader.h" +#include "TriggerData.h" +#include "VTPData.h" #include "Particle.h" #include "Track.h" #include "Vertex.h" diff --git a/event/include/EventHeader.h b/event/include/EventHeader.h index 5e97f4d71..8fa3194ee 100644 --- a/event/include/EventHeader.h +++ b/event/include/EventHeader.h @@ -19,6 +19,11 @@ //----------// #include +//----------// +// event // +//----------// +#include "TriggerData.h" + class EventHeader : public TObject { public: @@ -263,6 +268,21 @@ class EventHeader : public TObject { */ double getRfTime(const int channel) const { return rf_times_[channel]; }; + /** + * Set the Trigger Data. + * + * @param trigData The parsed trigger data + * + */ + void setTriggerData(TriggerData* trigData) { tdata = trigData; }; + + /** + * Get the RF time. + * + * @return The parsed trigger data + */ + TriggerData* getTriggerData() { return tdata; }; + void Print(); private: @@ -339,6 +359,9 @@ class EventHeader : public TObject { /** The RF time */ double rf_times_[2]; + /** The parsed trigger data */ + TriggerData* tdata{nullptr}; + ClassDef(EventHeader, 1); }; // EventHeader diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index fb8778955..2f487caa1 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -9,6 +9,8 @@ #pragma link C++ class CalCluster+; #pragma link C++ class CalHit+; #pragma link C++ class EventHeader+; +#pragma link C++ class TriggerData+; +#pragma link C++ class VTPData+; #pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class Vertex+; diff --git a/event/include/Track.h b/event/include/Track.h index d0504c2db..881616e72 100644 --- a/event/include/Track.h +++ b/event/include/Track.h @@ -23,7 +23,7 @@ //TODO static? namespace TRACKINFO { - enum STRATEGY {MATCH = 0, S345, S456, S123C4, S123C5, GBL}; + enum STRATEGY {MATCH = 0, S345, S456, S123C4, S123C5, GBL}; } class Track : public TObject { @@ -45,13 +45,13 @@ class Track : public TObject { * @param hit : A TrackerHit object */ void addHit(TObject* hit); - + /** - * @return A reference to the hits associated with this track. - */ + * @return A reference to the hits associated with this track. + */ TRefArray* getSvtHits() const { return tracker_hits_; }; - /** + /** * Set the track parameters. * * @param d0 Distance of closest approach to the reference point. @@ -67,20 +67,20 @@ class Track : public TObject { const double omega, const double tan_lambda, const double z0); - + /** @return The track parameters. */ std::vector getTrackParameters(); - double getD0 () const {return d0_;}; - double getPhi () const {return phi0_;}; - double getOmega () const {return omega_;}; - double getTanLambda() const {return tan_lambda_;}; - double getZ0 () const {return z0_;}; - + double getD0 () const {return d0_;}; + double getPhi () const {return phi0_;}; + double getOmega () const {return omega_;}; + double getTanLambda() const {return tan_lambda_;}; + double getZ0 () const {return z0_;}; - void setNdf(const float ndf) {ndf_ = ndf;}; - double getNdf() const {return ndf_;}; + + void setNdf(const float ndf) {ndf_ = ndf;}; + double getNdf() const {return ndf_;}; /** * Set the chi^2 of the fit to the track. @@ -88,19 +88,19 @@ class Track : public TObject { * @param chi2 The chi^2 of the fit to the track. */ void setChi2(const double chi2) { chi2_ = chi2; }; - + /** @return the chi^2 of the fit to the track. */ double getChi2() const { return chi2_; }; - /** @return the chi^2 / ndf of the fit to the track. */ + /** @return the chi^2 / ndf of the fit to the track. */ double getChi2Ndf() const { - //avoid check for 0 - if (ndf_ > 1e-6) - return chi2_; - else - return -999; - }; - + //avoid check for 0 + if (ndf_ > 1e-6) + return chi2_; + else + return -999; + }; + /** * Set the isolation variable of the given layer. * @@ -169,23 +169,23 @@ class Track : public TObject { /** @return The track type. */ int getType() const { return type_; }; - /** @return The track decoded type: GSSSSM. */ - - //bit1 - bool is345Seed () const { return ((type_ >> 1) & 0x1);} - - bool is456Seed () const { return ((type_ >> 2) & 0x1);} - - bool is123SeedC4 () const { return ((type_ >> 3) & 0x1);} - - bool is123SeedC5 () const { return ((type_ >> 4) & 0x1);} - - bool isMatchedTrack() const { return (type_ & 0x1);} - - bool isGBLTrack () const { return ((type_ >> 5) & 0x1);} - - bool isStrategy(TRACKINFO::STRATEGY strategy) {return (type_ >> strategy) & 0x1;}; - + /** @return The track decoded type: GSSSSM. */ + + //bit1 + bool is345Seed () const { return ((type_ >> 1) & 0x1);} + + bool is456Seed () const { return ((type_ >> 2) & 0x1);} + + bool is123SeedC4 () const { return ((type_ >> 3) & 0x1);} + + bool is123SeedC5 () const { return ((type_ >> 4) & 0x1);} + + bool isMatchedTrack() const { return (type_ & 0x1);} + + bool isGBLTrack () const { return ((type_ >> 5) & 0x1);} + + bool isStrategy(TRACKINFO::STRATEGY strategy) {return (type_ >> strategy) & 0x1;}; + /** * Set the track charge. * @@ -208,9 +208,9 @@ class Track : public TObject { */ void setMomentum(std::vector momentum); - /** @return The track momentum. */ + /** @return The track momentum. */ std::vector getMomentum() { return {px_, py_, pz_}; }; - + /** * Set the lambda kink of the given layer. * @@ -218,7 +218,7 @@ class Track : public TObject { * @param lambda_kink The lambda kink value. */ void setLambdaKink(const int layer, const double lambda_kink) { lambda_kinks_[layer] = lambda_kink; } - + /** * Get the lambda kink value of the given layer. * @@ -226,7 +226,7 @@ class Track : public TObject { * @return The lambda kink value of the given layer. */ double getLambdaKink(const int layer) const { return lambda_kinks_[layer]; } - + /** * Set the phi kink of the given layer. * @@ -258,22 +258,22 @@ class Track : public TObject { */ int getTrackerHitCount() const { return n_hits_; }; - /** Set number of shared 3D hits */ - void setNShared(const int nShared) { nShared_ = nShared;}; + /** Set number of shared 3D hits */ + void setNShared(const int nShared) { nShared_ = nShared;}; + + int getNShared() const {return nShared_;}; + + void setSharedLy0(const bool isShared) {SharedLy0_ = isShared;}; + void setSharedLy1(const bool isShared) {SharedLy1_ = isShared;}; - int getNShared() const {return nShared_;}; + bool getSharedLy0() const {return SharedLy0_;}; + bool getSharedLy1() const {return SharedLy1_;}; - void setSharedLy0(const bool isShared) {SharedLy0_ = isShared;}; - void setSharedLy1(const bool isShared) {SharedLy1_ = isShared;}; - bool getSharedLy0() const {return SharedLy0_;}; - bool getSharedLy1() const {return SharedLy1_;}; - + //TODO doc - //TODO doc + void Print (Option_t *option="") const; - void Print (Option_t *option="") const; - private: /** Reference to the 3D hits associated with this track. */ @@ -296,13 +296,13 @@ class Track : public TObject { /** The distance of closest approach to the reference point. */ double d0_{-999}; - + /** * The azimuthal angle of the momentum at the position of closest * approach to the reference point. - */ + */ double phi0_{-999}; - + /** * The track curvature. The curvature is positive (negative) if the particle has a * positive (negative) charge. @@ -314,37 +314,37 @@ class Track : public TObject { * the helix in the xz plane. */ double tan_lambda_{-999}; - + /** * The y position of the track at the distance of closest approach * in the xz plane. */ double z0_{-999}; - + /** The chi^2 of the track fit. */ double chi2_{-999}; - /** The ndfs of the track fit. */ - double ndf_{0.}; + /** The ndfs of the track fit. */ + double ndf_{0.}; /** * The time of the track. This is currently the average time of all * hits composing the track. */ double track_time_{-999}; - + /** The x position of the extrapolated track at the Ecal face. */ double x_at_ecal_{-999}; - + /** The y position of the extrapolated track at the Ecal face. */ double y_at_ecal_{-999}; - + /** The z position of the extrapolated track at the Ecal face. */ double z_at_ecal_{-999}; - + /** Array used to store the lambda kinks for each of the sensor layers. */ double lambda_kinks_[14]; - + /** Array used to store the phi kinks for each of the sensor layers. */ double phi_kinks_[14]; @@ -356,16 +356,16 @@ class Track : public TObject { /** Track charge. */ int charge_{0}; - /** N Shared hits. */ - int nShared_{0}; + /** N Shared hits. */ + int nShared_{0}; + + /** Has Ly0 Shared hits. */ + bool SharedLy0_{false}; - /** Has Ly0 Shared hits. */ - bool SharedLy0_{false}; + /** Has Ly1 Shared hits. */ + bool SharedLy1_{false}; - /** Has Ly1 Shared hits. */ - bool SharedLy1_{false}; - ClassDef(Track, 1); }; // Track diff --git a/event/include/TriggerData.h b/event/include/TriggerData.h index 7efd08f4d..bf8417663 100644 --- a/event/include/TriggerData.h +++ b/event/include/TriggerData.h @@ -7,6 +7,11 @@ #ifndef _TRIGGER_DATA_H_ #define _TRIGGER_DATA_H_ +//----------// +// event // +//----------// +#include "VTPData.h" + //----------// // LCIO // //----------// @@ -22,25 +27,11 @@ class TriggerData { * @param trigger_data : The LCGenericObeject that is being used to * store the data from the TI */ + TriggerData(){}; TriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data); - /** @return The trigger time. */ - double getTime() const { return time_stamp_; }; - - /** @return True if the event registered a single0 trigger. */ - bool isSingle0Trigger() const { return single0_; }; - - /** @return True if the event registered a single1 trigger. */ - bool isSingle1Trigger() const { return single1_; }; - - /** @return True if the event registered a pair0 trigger. */ - bool isPair0Trigger() const { return pair0_; }; - - /** @return True if the event registered a pair1 trigger. */ - bool isPair1Trigger() const { return pair1_; }; - - /** @return True if the event registered a pulser trigger. */ - bool isPulserTrigger() const { return pulser_; }; + /** @return The parsed VTP data. */ + VTPData* getVTPData() const { return vtpData; }; private: @@ -50,20 +41,9 @@ class TriggerData { /** Trigger time stamp. */ long time_stamp_{-9999}; - /** Flag indicating whether a single0 trigger was registered. */ - bool single0_{0}; - - /** Flag indicating whether a single1 trigger was registered. */ - bool single1_{0}; - - /** Flag indicating whether a pair0 trigger was registered. */ - bool pair0_{0}; - - /** Flag indicating whether a pair1 trigger was registered. */ - bool pair1_{0}; - - /** Flag indicating whether a pulser trigger was registered. */ - bool pulser_{0}; + /** VTP data parser. */ + VTPData * vtpData{nullptr}; + }; #endif // __TRIGGER_DATA_H__ diff --git a/event/include/VTPData.h b/event/include/VTPData.h new file mode 100644 index 000000000..ffabcd2f0 --- /dev/null +++ b/event/include/VTPData.h @@ -0,0 +1,157 @@ +/** + * @file VTPData.h + * @brief Class used to decode VTP words. + * @author: Maurik Holtrop, University of New Hampsire + * @author: Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef _VTP_DATA_H_ +#define _VTP_DATA_H_ + +#include + +//----------// +// LCIO // +//----------// +#include + +class VTPData { + + public: + struct { + unsigned int blocklevel: 8; // bit 0-7 + unsigned int blocknum: 10; // bit 8-17 + unsigned int nothing: 4; // bit 18-21 + unsigned int slotid: 5; // bit 22-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit31 + } blockHeader; + + struct { + unsigned int nwords: 22; // bit 0-21 + unsigned int slotid: 5; // bit 22-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + } blockTail; + + struct { + unsigned int eventnum: 27; // bit 0-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + } eventHeader; + + unsigned long trigTime; + + struct hpsCluster { + int X: 6; // bit 0-5 + int Y: 4; // bit 6-9 + unsigned int E: 13; // bit 10-22 + unsigned int subtype: 4; // bit 23-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + unsigned int T: 10; // bit 0-9 + unsigned int N: 4; // bit 10-13 Second word + unsigned int nothing: 18; // bit 14-31 Second word not used. + }; + + std::vector clusters; + + struct hpsSingleTrig { + unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. + struct { + bool emin: 1; + bool emax: 1; + bool nmin: 1; + bool xmin: 1; + bool pose: 1; // position dependent energy thresh. + bool hodo1c: 1; // hodoscope layer 1 coincidence. + bool hodo2c: 1; // hodoscope layer 2 coincidence. + bool hodogeo:1; // hodoscope layer 1 geometry matched to layer 2 geometry + bool hodoecal:1;// hodoscope layer 1 and 2 geometry mached to ecal cluster x. + } Pass; // 9 bits: bit 10-18 + bool topnbot: 1; // bit 19 + unsigned int inst:3; // bit 20-22 = single cluster trigger bit instance. + unsigned int subtype: 4; // bit 23-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + }; + + std::vector singletrigs; + + struct hpsPairTrig { + unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. + struct { + bool clusesum: 1; + bool clusedif: 1; + bool eslope: 1; + bool coplane: 1; + unsigned int dummy: 5; + } Pass; // 9 bits: bit 10-18 + bool topnbot: 1; // bit 19 - dummy! + unsigned int inst:3; // bit 20-22 = single cluster trigger bit instance. + unsigned int subtype: 4; // bit 23-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + }; + + std::vector pairtrigs; + + struct hpsCalibTrig { + unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. + unsigned int reserved: 9; + struct { + bool cosmic: 1; + bool led: 1; + bool hodoscope: 1; + bool puler: 1; + } trigtype; + unsigned int subtype: 4; // bit 23-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + }; + + std::vector calibtrigs; + + struct hpsClusterMult { + unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. + unsigned int multtop: 4; + unsigned int multbot: 4; + unsigned int multtot: 4; + bool bitinst: 1; + unsigned int subtype: 4; // bit 23-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + }; + + std::vector clustermult; // Cluster multiplicity. + + struct hpsFEETrig { + unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. + unsigned int region: 7; + unsigned int reserved: 6; + unsigned int subtype: 4; // bit 23-26 + unsigned int type: 4; // bit 27-30 + bool istype: 1; // bit 31 + }; + + std::vector feetrigger; // Cluster multiplicity. + + public: + VTPData(){}; + VTPData(EVENT::LCGenericObject* vtp_data); + ~VTPData(){}; + + void Clear(){ + clusters.clear(); + singletrigs.clear(); + pairtrigs.clear(); + calibtrigs.clear(); + clustermult.clear(); + feetrigger.clear(); + }; + + void parseVTPData(EVENT::LCGenericObject* vtp_data); + +}; + +#endif // __VTP_DATA_H__ diff --git a/event/src/TriggerData.cxx b/event/src/TriggerData.cxx index dc21f6903..860af9937 100644 --- a/event/src/TriggerData.cxx +++ b/event/src/TriggerData.cxx @@ -12,73 +12,5 @@ TriggerData::TriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObjec void TriggerData::parseTriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data) { - //std::cout << trigger_data->getNInt() << " VTP words" << std::endl; - for(int i = 0; i < vtp_data->getNInt(); i++) - { - int vtp_data_int = vtp_data->getIntVal(i); - if(!(vtp_data_int & 1<<31)) continue; - int type = (vtp_data_int>>27)&0x0F; - int subtype = -1; - switch (type) - { - case 0: // Block Header - //std::cout << i << "VTP Block Header Word" << std::endl; - break; - case 1: // Block Tail - //std::cout << i << "VTP Block Tail Word" << std::endl; - break; - case 2: // Event Header - //std::cout << i << "VTP Event Header Word" << std::endl; - break; - case 3: // Trigger time - time_stamp_ = (vtp_data_int & 0x00FFFFFF) + ((vtp_data->getIntVal(i+1)& 0x00FFFFFF )<<24); - i++; - break; - case 12: // Expansion type - subtype = (vtp_data_int>>23)&0x0F; - switch(subtype){ - case 2: // HPS Cluster - //std::cout << i << "VTP Cluster Word" << std::endl; - break; - case 3: // HPS Single Cluster - //std::cout << i << "VTP Single Cluster Word" << std::endl; - break; - case 4: // HPS Pair Trigger - //std::cout << i << "VTP Pair Trigger Word" << std::endl; - break; - case 5: // HPS Calibration Trigger - //std::cout << i << "VTP Calibration Trigger Word: " << trigger_data_int << std::endl; - break; - case 6: // HPS Cluster Multiplicity Trigger - //std::cout << i << "VTP Cluster Multiplicity Trigger Word" << std::endl; - break; - case 7: // HPS FEE Trigger - //std::cout << i << "VTP FEE Trigger Word" << std::endl; - break; - default: - //std::cout << "At " << i << " invalid HPS type: " << type << " subtype: " << subtype << std::endl; - break; - } - - break; - case 14: - //std::cout << i << "VTP data type not valid: " << type << std::endl; - break; - default: - //std::cout << i << "I was not expecting a VTP data type of " << type << std::endl; - break; - } - - } - - //Parse data from trigger supervisor - for(int i = 0; i < ts_data->getNInt(); i++) - { - break; - } - single0_ = 0; - single1_ = 0; - pair0_ = 0; - pair1_ = 0; - pulser_ = 0; + vtpData = new VTPData(vtp_data); } diff --git a/event/src/VTPData.cxx b/event/src/VTPData.cxx new file mode 100644 index 000000000..690b521d2 --- /dev/null +++ b/event/src/VTPData.cxx @@ -0,0 +1,85 @@ +/** + * @file VTPData.cxx + * @brief Class used to decode VTP words. + * @author: Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#include "VTPData.h" + +VTPData::VTPData(EVENT::LCGenericObject* vtp_data) { + this->parseVTPData(vtp_data); +} + +void VTPData::parseVTPData(EVENT::LCGenericObject* vtp_data) +{ + // First Clear out all the old data. + Clear(); + for(int i=0; igetNInt(); ++i) + { + int data = vtp_data->getIntVal(i); + if(!(data & 1<<31)) continue; + int type = (data>>27)&0x0F; + int subtype; + switch (type) + { + case 0: // Block Header + ((unsigned int *)&blockHeader)[0] = data; + break; + case 1: // Block Tail + ((unsigned int *)&blockTail)[0] = data; + break; + case 2: // Event Header + ((unsigned int *)&eventHeader)[0] = data; + break; + case 3: // Trigger time + trigTime = (data & 0x00FFFFFF) + ((vtp_data->getIntVal(i+1)& 0x00FFFFFF )<<24); + i++; + break; + case 12: // Expansion type + subtype = (data>>23)&0x0F; + switch(subtype){ + case 2: // HPS Cluster + hpsCluster clus; + ((unsigned long *)&clus)[0] = ((long)data + (((long)vtp_data->getIntVal(i+1))<<32) ); + clusters.push_back(clus); + break; + case 3: // HPS Single Cluster + hpsSingleTrig strig; + ((unsigned long *)&strig)[0] = data; + singletrigs.push_back(strig); + break; + case 4: // HPS Pair Trigger + hpsPairTrig ptrig; + ((unsigned long *)&ptrig)[0] = data; + pairtrigs.push_back(ptrig); + break; + case 5: // HPS Calibration Trigger + hpsCalibTrig ctrig; + ((unsigned long *)&ctrig)[0] = data; + calibtrigs.push_back(ctrig); + break; + case 6: // HPS Cluster Multiplicity Trigger + hpsClusterMult clmul; + ((unsigned long *)&clmul)[0] = data; + clustermult.push_back(clmul); + break; + case 7: // HPS FEE Trigger + hpsFEETrig fee; + ((unsigned long *)&fee)[0] = data; + feetrigger.push_back(fee); + break; + default: + std::cout << "At " << i << " invalid HPS type: " << type << " subtype: " << subtype << std::endl; + break; + } + + break; + case 14: + std::cout << i << "VTP data type not valid: " << type << std::endl; + break; + default: + std::cout << i << "I was not expecting a VTP data type of " << type << std::endl; + break; + } + } +} diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index 986a1e4c6..d69a10641 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -70,14 +70,13 @@ bool EventProcessor::process(IEvent* ievent) { EVENT::LCGenericObject* ts_datum = static_cast(ts_data->getElementAt(0)); - TriggerData* tdata = new TriggerData(vtp_datum, ts_datum); - header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); - header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); - header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); - header.setPair1Trigger(static_cast(tdata->isPair1Trigger())); - header.setPulserTrigger(static_cast(tdata->isPulserTrigger())); - - delete tdata; + header.setTriggerData(new TriggerData(vtp_datum, ts_datum)); + //header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); + //header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); + //header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); + //header.setPair1Trigger(static_cast(tdata->isPair1Trigger())); + //header.setPulserTrigger(static_cast(tdata->isPulserTrigger())); + } catch(EVENT::DataNotAvailableException e) { // It's fine if the event doesn't have a trigger bank. } diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx index eebee4185..940ff13ab 100644 --- a/processors/src/TrackingProcessor.cxx +++ b/processors/src/TrackingProcessor.cxx @@ -3,135 +3,135 @@ #include "utilities.h" TrackingProcessor::TrackingProcessor(const std::string& name, Process& process) - : Processor(name, process) { -} + : Processor(name, process) { + } TrackingProcessor::~TrackingProcessor() { } void TrackingProcessor::initialize(TTree* tree) { - tree->Branch(Collections::GBL_TRACKS,&tracks_); - tree->Branch(Collections::TRACKER_HITS, &hits_); - tree->Branch(Collections::RAW_SVT_HITS, &rawhits_); - + tree->Branch(Collections::GBL_TRACKS,&tracks_); + tree->Branch(Collections::TRACKER_HITS, &hits_); + tree->Branch(Collections::RAW_SVT_HITS, &rawhits_); + } bool TrackingProcessor::process(IEvent* ievent) { - - - //Clean up - if (tracks_.size() > 0 ) { - for (std::vector::iterator it = tracks_.begin(); it != tracks_.end(); ++it) { - delete *it; + + + //Clean up + if (tracks_.size() > 0 ) { + for (std::vector::iterator it = tracks_.begin(); it != tracks_.end(); ++it) { + delete *it; + } + tracks_.clear(); } - tracks_.clear(); - } - - if (hits_.size() > 0) { - for (std::vector::iterator it = hits_.begin(); it != hits_.end(); ++it) { - delete *it; + + if (hits_.size() > 0) { + for (std::vector::iterator it = hits_.begin(); it != hits_.end(); ++it) { + delete *it; + } + hits_.clear(); } - hits_.clear(); - } - if (rawhits_.size() > 0) { - for (std::vector::iterator it = rawhits_.begin(); it != rawhits_.end(); ++it) { - delete *it; + if (rawhits_.size() > 0) { + for (std::vector::iterator it = rawhits_.begin(); it != rawhits_.end(); ++it) { + delete *it; + } + rawhits_.clear(); } + + + tracks_.clear(); + hits_.clear(); rawhits_.clear(); - } - - - tracks_.clear(); - hits_.clear(); - rawhits_.clear(); - - Event* event = static_cast (ievent); - // Get the collection of 3D hits from the LCIO event. If no such collection - // exist, a DataNotAvailableException is thrown - - // Get decoders to read cellids - UTIL::BitField64 decoder("system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12"); - - UTIL::LCRelationNavigator* rawTracker_hit_fits_nav = nullptr; - EVENT::LCCollection* raw_svt_hit_fits = nullptr; - //Check to see if fits are in the file - auto evColls = event->getLCEvent()->getCollectionNames(); - auto it = std::find (evColls->begin(), evColls->end(), Collections::RAW_SVT_HIT_FITS); - bool hasFits = true; - if(it == evColls->end()) hasFits = false; - if(hasFits) + + Event* event = static_cast (ievent); + // Get the collection of 3D hits from the LCIO event. If no such collection + // exist, a DataNotAvailableException is thrown + + // Get decoders to read cellids + UTIL::BitField64 decoder("system:6,barrel:3,layer:4,module:12,sensor:1,side:32:-2,strip:12"); + + UTIL::LCRelationNavigator* rawTracker_hit_fits_nav = nullptr; + EVENT::LCCollection* raw_svt_hit_fits = nullptr; + //Check to see if fits are in the file + auto evColls = event->getLCEvent()->getCollectionNames(); + auto it = std::find (evColls->begin(), evColls->end(), Collections::RAW_SVT_HIT_FITS); + bool hasFits = true; + if(it == evColls->end()) hasFits = false; + if(hasFits) { - raw_svt_hit_fits = event->getLCCollection(Collections::RAW_SVT_HIT_FITS); - // Heap an LCRelation navigator which will allow faster access - rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); + raw_svt_hit_fits = event->getLCCollection(Collections::RAW_SVT_HIT_FITS); + // Heap an LCRelation navigator which will allow faster access + rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); } - - // Get all track collections from the event - EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); - - - // Loop over all the LCIO Tracks and add them to the HPS event. - for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { - - // Get a LCIO Track from the LCIO event - EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); - - // Get the collection of LCRelations between GBL kink data variables - // (GBLKinkData) and the corresponding track. - EVENT::LCCollection* gbl_kink_data = - static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); - - // Get the collection of LCRelations between track data variables - // (TrackData) and the corresponding track. - EVENT::LCCollection* track_data = static_cast( - event->getLCCollection(Collections::TRACK_DATA_REL)); - - - // Add a track to the event - Track* track = utils::buildTrack(lc_track,gbl_kink_data,track_data); - - - // Get the collection of 3D hits associated with a LCIO Track - EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); - - // Iterate through the collection of 3D hits (TrackerHit objects) - // associated with a track, find the corresponding hits in the HPS - // event and add references to the track - - - for (auto lc_tracker_hit : lc_tracker_hits) { - - TrackerHit* tracker_hit = utils::buildTrackerHit(static_cast(lc_tracker_hit)); - - std::vector rawSvthitsOn3d; - utils::addRawInfoTo3dHit(tracker_hit,static_cast(lc_tracker_hit), - raw_svt_hit_fits,&rawSvthitsOn3d); - - - for (auto rhit : rawSvthitsOn3d) - rawhits_.push_back(rhit); - - rawSvthitsOn3d.clear(); - - if (_debug) - std::cout<getRawHits()->GetEntries()<addHit(tracker_hit); - hits_.push_back(tracker_hit); - }//tracker hits - tracks_.push_back(track); - }// tracks - - //delete - if (rawTracker_hit_fits_nav) { - delete rawTracker_hit_fits_nav; rawTracker_hit_fits_nav = nullptr;} - - //event->addCollection("TracksInfo", &tracks_); - //event->addCollection("TrackerHitsInfo", &hits_); - //event->addCollection("TrackerHitsRawInfo", &rawhits_); - - return true; + + // Get all track collections from the event + EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); + + + // Loop over all the LCIO Tracks and add them to the HPS event. + for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { + + // Get a LCIO Track from the LCIO event + EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); + + // Get the collection of LCRelations between GBL kink data variables + // (GBLKinkData) and the corresponding track. + EVENT::LCCollection* gbl_kink_data = + static_cast(event->getLCCollection(Collections::KINK_DATA_REL)); + + // Get the collection of LCRelations between track data variables + // (TrackData) and the corresponding track. + EVENT::LCCollection* track_data = static_cast( + event->getLCCollection(Collections::TRACK_DATA_REL)); + + + // Add a track to the event + Track* track = utils::buildTrack(lc_track,gbl_kink_data,track_data); + + + // Get the collection of 3D hits associated with a LCIO Track + EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits(); + + // Iterate through the collection of 3D hits (TrackerHit objects) + // associated with a track, find the corresponding hits in the HPS + // event and add references to the track + + + for (auto lc_tracker_hit : lc_tracker_hits) { + + TrackerHit* tracker_hit = utils::buildTrackerHit(static_cast(lc_tracker_hit)); + + std::vector rawSvthitsOn3d; + utils::addRawInfoTo3dHit(tracker_hit,static_cast(lc_tracker_hit), + raw_svt_hit_fits,&rawSvthitsOn3d); + + + for (auto rhit : rawSvthitsOn3d) + rawhits_.push_back(rhit); + + rawSvthitsOn3d.clear(); + + if (_debug) + std::cout<getRawHits()->GetEntries()<addHit(tracker_hit); + hits_.push_back(tracker_hit); + }//tracker hits + tracks_.push_back(track); + }// tracks + + //delete + if (rawTracker_hit_fits_nav) { + delete rawTracker_hit_fits_nav; rawTracker_hit_fits_nav = nullptr;} + + //event->addCollection("TracksInfo", &tracks_); + //event->addCollection("TrackerHitsInfo", &hits_); + //event->addCollection("TrackerHitsRawInfo", &rawhits_); + + return true; } void TrackingProcessor::finalize() { From f1cffb805b2638039fa5567b48c103ff78904539 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 7 Oct 2019 16:42:48 -0700 Subject: [PATCH 133/314] VTP data now properly parsed into tree --- event/include/Collections.h | 1 + event/include/Event.h | 2 +- event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 16 +++ event/include/RawSvtHit.h | 22 ++-- event/include/TriggerData.h | 30 +++-- event/include/VTPData.h | 184 +++++++++++++-------------- event/src/Event.cxx | 2 +- event/src/TriggerData.cxx | 16 ++- event/src/VTPData.cxx | 182 +++++++++++++++----------- processing/src/Process.cxx | 122 +++++++++--------- processors/include/EventProcessor.h | 3 + processors/src/EventProcessor.cxx | 156 +++++++++++++++++++++++ processors/src/TrackingProcessor.cxx | 2 +- 14 files changed, 491 insertions(+), 248 deletions(-) diff --git a/event/include/Collections.h b/event/include/Collections.h index 1ea810107..11ea7ff27 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -2,6 +2,7 @@ * @file Collection.h * @brief List of collection names. * @author Omar Moreno, SLAC National Accelerator Laboratory + * @author Cameron Bravo, SLAC National Accelerator Laboratory */ #ifndef _COLLECTIONS_H_ diff --git a/event/include/Event.h b/event/include/Event.h index 08030880f..dc1223682 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -43,7 +43,7 @@ class Event : public IEvent { ~Event(); /** - * + * Add a TObject to the event. */ virtual void add(const std::string name, TObject* object); diff --git a/event/include/EventDef.h b/event/include/EventDef.h index 5635a65d9..ab28849d1 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -5,6 +5,7 @@ #include "EventHeader.h" #include "TriggerData.h" #include "VTPData.h" +#include "TSData.h" #include "Particle.h" #include "Track.h" #include "Vertex.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 2f487caa1..916111737 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -11,6 +11,16 @@ #pragma link C++ class EventHeader+; #pragma link C++ class TriggerData+; #pragma link C++ class VTPData+; +#pragma link C++ class VTPData::bHeader+; +#pragma link C++ class VTPData::bTail+; +#pragma link C++ class VTPData::eHeader+; +#pragma link C++ class VTPData::hpsCluster+; +#pragma link C++ class VTPData::hpsSingleTrig+; +#pragma link C++ class VTPData::hpsPairTrig+; +#pragma link C++ class VTPData::hpsCalibTrig+; +#pragma link C++ class VTPData::hpsClusterMult+; +#pragma link C++ class VTPData::hpsFEETrig+; +#pragma link C++ class TSData+; #pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class Vertex+; @@ -28,4 +38,10 @@ #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #endif diff --git a/event/include/RawSvtHit.h b/event/include/RawSvtHit.h index 439fde131..bcc8fdfd5 100644 --- a/event/include/RawSvtHit.h +++ b/event/include/RawSvtHit.h @@ -85,23 +85,23 @@ class RawSvtHit : public TObject { /** Get the strip */ int getStrip(); - /** Get the t0 fit parameter */ - double getT0() {return fit_[0];} + /** Get the t0 fit parameter */ + double getT0() {return fit_[0];} - /** Get the t0 err fit parameter */ - double getT0err() {return fit_[1];} + /** Get the t0 err fit parameter */ + double getT0err() {return fit_[1];} - /** Get the amplitude fit parameter */ - double getAmp() {return fit_[2];} + /** Get the amplitude fit parameter */ + double getAmp() {return fit_[2];} - /** Get the amplitude error fit parameter */ - double getAmpErr() {return fit_[3];} + /** Get the amplitude error fit parameter */ + double getAmpErr() {return fit_[3];} - /** Get the chiSq probability */ - double getChiSq() {return fit_[4];} + /** Get the chiSq probability */ + double getChiSq() {return fit_[4];} ClassDef(RawSvtHit, 1); - + private: diff --git a/event/include/TriggerData.h b/event/include/TriggerData.h index bf8417663..9f7606dec 100644 --- a/event/include/TriggerData.h +++ b/event/include/TriggerData.h @@ -1,7 +1,8 @@ /** * @file TriggerData.h - * @brief Class used to decode TI information. + * @brief Class used to decode VTP and TS information. * @author: Omar Moreno, SLAC National Accelerator Laboratory + * @author: Cameron Bravo, SLAC National Accelerator Laboratory */ #ifndef _TRIGGER_DATA_H_ @@ -17,21 +18,37 @@ //----------// #include -class TriggerData { +//----------// +// ROOT // +//----------// +#include "TObject.h" + +class TriggerData : public TObject { public: + // Constructor + TriggerData(); + /** * Constructor * * @param trigger_data : The LCGenericObeject that is being used to * store the data from the TI */ - TriggerData(){}; TriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data); - /** @return The parsed VTP data. */ - VTPData* getVTPData() const { return vtpData; }; + // Destructor + ~TriggerData(); + + //Reset the trigger object + void Clear(); + + /** VTP data parser. */ + VTPData * vtpData{nullptr}; + + + ClassDef(TriggerData, 1); private: @@ -41,9 +58,6 @@ class TriggerData { /** Trigger time stamp. */ long time_stamp_{-9999}; - /** VTP data parser. */ - VTPData * vtpData{nullptr}; - }; #endif // __TRIGGER_DATA_H__ diff --git a/event/include/VTPData.h b/event/include/VTPData.h index ffabcd2f0..db4ce9c9e 100644 --- a/event/include/VTPData.h +++ b/event/include/VTPData.h @@ -9,139 +9,139 @@ #define _VTP_DATA_H_ #include +#include //----------// -// LCIO // +// ROOT // //----------// -#include +#include -class VTPData { +class VTPData : public TObject { public: - struct { - unsigned int blocklevel: 8; // bit 0-7 - unsigned int blocknum: 10; // bit 8-17 - unsigned int nothing: 4; // bit 18-21 - unsigned int slotid: 5; // bit 22-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit31 - } blockHeader; - - struct { - unsigned int nwords: 22; // bit 0-21 - unsigned int slotid: 5; // bit 22-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 - } blockTail; - - struct { - unsigned int eventnum: 27; // bit 0-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 - } eventHeader; + struct bHeader { + unsigned int blocklevel; // 8 bits 0-7 + unsigned int blocknum; // 10 bits 8-17 + unsigned int nothing; // 4 bits 18-21 + unsigned int slotid; // 5 bits 22-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 + }; + bHeader blockHeader; + + struct bTail { + unsigned int nwords; // 22 bits 0-21 + unsigned int slotid; // 5 bits 22-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 + }; + bTail blockTail; + + struct eHeader { + unsigned int eventnum; // 27 bits 0-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 + }; + eHeader eventHeader; unsigned long trigTime; struct hpsCluster { - int X: 6; // bit 0-5 - int Y: 4; // bit 6-9 - unsigned int E: 13; // bit 10-22 - unsigned int subtype: 4; // bit 23-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 - unsigned int T: 10; // bit 0-9 - unsigned int N: 4; // bit 10-13 Second word - unsigned int nothing: 18; // bit 14-31 Second word not used. + int X; // 6 bits 0-5 + int Y; // 4 bits 6-9 + unsigned int E; // 13 bits 10-22 + unsigned int subtype; // 4 bits 23-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 + unsigned int T; // 10 bits 0-9 Second word + unsigned int N; // 4 bits 10-13 Second word + unsigned int nothing; // 18 bits 14-31 Second word not used. }; std::vector clusters; struct hpsSingleTrig { - unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. - struct { - bool emin: 1; - bool emax: 1; - bool nmin: 1; - bool xmin: 1; - bool pose: 1; // position dependent energy thresh. - bool hodo1c: 1; // hodoscope layer 1 coincidence. - bool hodo2c: 1; // hodoscope layer 2 coincidence. - bool hodogeo:1; // hodoscope layer 1 geometry matched to layer 2 geometry - bool hodoecal:1;// hodoscope layer 1 and 2 geometry mached to ecal cluster x. - } Pass; // 9 bits: bit 10-18 - bool topnbot: 1; // bit 19 - unsigned int inst:3; // bit 20-22 = single cluster trigger bit instance. - unsigned int subtype: 4; // bit 23-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 + unsigned int T; // 10 bits 0-9 Trigger time in 4ns units from the beginning of the readout window. + bool emin; // 1 bit 10 + bool emax; // 1 bit 11 + bool nmin; // 1 bit 12 + bool xmin; // 1 bit 13 + bool pose; // 1 bit 14 position dependent energy thresh. + bool hodo1c; // 1 bit 15 hodoscope layer 1 coincidence. + bool hodo2c; // 1 bit 16 hodoscope layer 2 coincidence. + bool hodogeo; // 1 bit 17 hodoscope layer 1 geometry matched to layer 2 geometry + bool hodoecal; // 1 bit 18 hodoscope layer 1 and 2 geometry mached to ecal cluster x. + bool topnbot; // 1 bit 19 + unsigned int inst; // 3 bits 20-22 = single cluster trigger bit instance. + unsigned int subtype; // 4 bits 23-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 }; std::vector singletrigs; struct hpsPairTrig { - unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. - struct { - bool clusesum: 1; - bool clusedif: 1; - bool eslope: 1; - bool coplane: 1; - unsigned int dummy: 5; - } Pass; // 9 bits: bit 10-18 - bool topnbot: 1; // bit 19 - dummy! - unsigned int inst:3; // bit 20-22 = single cluster trigger bit instance. - unsigned int subtype: 4; // bit 23-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 + unsigned int T; // bit 0-9 Trigger time in 4ns units from the beginning of the readout window. + bool clusesum; // 1 bit 10 + bool clusedif; // 1 bit 11 + bool eslope; // 1 bit 12 + bool coplane; // 1 bit 13 + unsigned int dummy; // 5 bits 14-18 + bool topnbot; // 1 bit 19 - dummy! + unsigned int inst; // 3 bits 20-22 = single cluster trigger bit instance. + unsigned int subtype; // 4 bits 23-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 }; std::vector pairtrigs; struct hpsCalibTrig { - unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. - unsigned int reserved: 9; - struct { - bool cosmic: 1; - bool led: 1; - bool hodoscope: 1; - bool puler: 1; - } trigtype; - unsigned int subtype: 4; // bit 23-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 + unsigned int T; // 10 bits 0-9 Time in 4ns units from the beginning of the readout window. + unsigned int reserved; // 9 bits 10-18 + bool cosmicTrig; // 1 bit 19 + bool LEDTrig; // 1 bit 20 + bool hodoTrig; // 1 bit 21 + bool pulserTrig; // 1 bit 22 + unsigned int subtype; // 4 bits 23-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 }; std::vector calibtrigs; struct hpsClusterMult { - unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. - unsigned int multtop: 4; - unsigned int multbot: 4; - unsigned int multtot: 4; - bool bitinst: 1; - unsigned int subtype: 4; // bit 23-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 + unsigned int T; // 10 bits 0-9 Time in 4ns units from the beginning of the readout window. + unsigned int multtop; // 4 bits 10-13 + unsigned int multbot; // 4 bits 14-17 + unsigned int multtot; // 4 bits 18-21 + bool bitinst; // 1 bit 22 + unsigned int subtype; // 4 bits 23-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 }; std::vector clustermult; // Cluster multiplicity. struct hpsFEETrig { - unsigned int T: 10; // bit 0-9 Trigger time in 4ns units referenced from the beginning of the readout window. - unsigned int region: 7; - unsigned int reserved: 6; - unsigned int subtype: 4; // bit 23-26 - unsigned int type: 4; // bit 27-30 - bool istype: 1; // bit 31 + unsigned int T; // 10 bits 0-9 Time in 4ns units from the beginning of the readout window. + unsigned int region; // 7 bits 10-16 + unsigned int reserved; // 6 bits 17-22 + unsigned int subtype; // 4 bits 23-26 + unsigned int type; // 4 bits 27-30 + bool istype; // 1 bit 31 }; std::vector feetrigger; // Cluster multiplicity. public: - VTPData(){}; - VTPData(EVENT::LCGenericObject* vtp_data); - ~VTPData(){}; + VTPData(); + ~VTPData(); + + void print(); void Clear(){ + TObject::Clear(); clusters.clear(); singletrigs.clear(); pairtrigs.clear(); @@ -150,7 +150,7 @@ class VTPData { feetrigger.clear(); }; - void parseVTPData(EVENT::LCGenericObject* vtp_data); + ClassDef(VTPData, 1); }; diff --git a/event/src/Event.cxx b/event/src/Event.cxx index fdab5acf1..5d6f22f56 100644 --- a/event/src/Event.cxx +++ b/event/src/Event.cxx @@ -45,7 +45,7 @@ void Event::addCollection(const std::string name, TClonesArray* collection) { // Add a branch with the given name to the event tree. branches_[name] = tree_->Branch(name.c_str(), collection, 1000000, 3); - // Keep track of which events were added to the event + // Keep track of which collections were added to the event objects_[name] = collection; } diff --git a/event/src/TriggerData.cxx b/event/src/TriggerData.cxx index 860af9937..4f0526ba4 100644 --- a/event/src/TriggerData.cxx +++ b/event/src/TriggerData.cxx @@ -6,11 +6,25 @@ #include "TriggerData.h" +ClassImp(TriggerData) + +TriggerData::TriggerData() + : TObject() { + } + +TriggerData::~TriggerData(){ + Clear(); +} + +void TriggerData::Clear(){ + TObject::Clear(); +} + TriggerData::TriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data) { this->parseTriggerData(vtp_data, ts_data); } void TriggerData::parseTriggerData(EVENT::LCGenericObject* vtp_data, EVENT::LCGenericObject* ts_data) { - vtpData = new VTPData(vtp_data); + //vtpData = new VTPData(vtp_data); } diff --git a/event/src/VTPData.cxx b/event/src/VTPData.cxx index 690b521d2..85acc9ed1 100644 --- a/event/src/VTPData.cxx +++ b/event/src/VTPData.cxx @@ -6,80 +6,118 @@ #include "VTPData.h" -VTPData::VTPData(EVENT::LCGenericObject* vtp_data) { - this->parseVTPData(vtp_data); -} +ClassImp(VTPData) + +VTPData::VTPData() + : TObject() { + } -void VTPData::parseVTPData(EVENT::LCGenericObject* vtp_data) -{ - // First Clear out all the old data. +//VTPData::VTPData(EVENT::LCGenericObject* vtp_data) : TObject() { +// this->parseVTPData(vtp_data); +//} + +VTPData::~VTPData(){ Clear(); - for(int i=0; igetNInt(); ++i) - { - int data = vtp_data->getIntVal(i); - if(!(data & 1<<31)) continue; - int type = (data>>27)&0x0F; - int subtype; - switch (type) - { - case 0: // Block Header - ((unsigned int *)&blockHeader)[0] = data; - break; - case 1: // Block Tail - ((unsigned int *)&blockTail)[0] = data; - break; - case 2: // Event Header - ((unsigned int *)&eventHeader)[0] = data; - break; - case 3: // Trigger time - trigTime = (data & 0x00FFFFFF) + ((vtp_data->getIntVal(i+1)& 0x00FFFFFF )<<24); - i++; - break; - case 12: // Expansion type - subtype = (data>>23)&0x0F; - switch(subtype){ - case 2: // HPS Cluster - hpsCluster clus; - ((unsigned long *)&clus)[0] = ((long)data + (((long)vtp_data->getIntVal(i+1))<<32) ); - clusters.push_back(clus); - break; - case 3: // HPS Single Cluster - hpsSingleTrig strig; - ((unsigned long *)&strig)[0] = data; - singletrigs.push_back(strig); - break; - case 4: // HPS Pair Trigger - hpsPairTrig ptrig; - ((unsigned long *)&ptrig)[0] = data; - pairtrigs.push_back(ptrig); - break; - case 5: // HPS Calibration Trigger - hpsCalibTrig ctrig; - ((unsigned long *)&ctrig)[0] = data; - calibtrigs.push_back(ctrig); - break; - case 6: // HPS Cluster Multiplicity Trigger - hpsClusterMult clmul; - ((unsigned long *)&clmul)[0] = data; - clustermult.push_back(clmul); - break; - case 7: // HPS FEE Trigger - hpsFEETrig fee; - ((unsigned long *)&fee)[0] = data; - feetrigger.push_back(fee); - break; - default: - std::cout << "At " << i << " invalid HPS type: " << type << " subtype: " << subtype << std::endl; - break; - } +} - break; - case 14: - std::cout << i << "VTP data type not valid: " << type << std::endl; - break; - default: - std::cout << i << "I was not expecting a VTP data type of " << type << std::endl; - break; - } +void VTPData::print(){ + using namespace std; + cout << "blockHeader.blocklevel: " << blockHeader.blocklevel << endl; + cout << "blockHeader.blocknum: " << blockHeader.blocknum << endl; + cout << "blockHeader.nothing: " << blockHeader.nothing << endl; + cout << "blockHeader.slotid: " << blockHeader.slotid << endl; + cout << "blockHeader.type: " << blockHeader.type << endl; + cout << "blockHeader.istype: " << blockHeader.istype << endl; + cout << "blockTail.nwords: " << blockTail.nwords << endl; + cout << "blockTail.slotid: " << blockTail.slotid << endl; + cout << "blockTail.type: " << blockTail.type << endl; + cout << "blockTail.istype: " << blockTail.istype << endl; + cout << "eventHeader.eventnum: " << eventHeader.eventnum << endl; + cout << "eventHeader.type: " << eventHeader.type << endl; + cout << "eventHeader.istype: " << eventHeader.istype << endl; + cout << "trigTime: " << trigTime << std::endl; + for(int i = 0; i < clusters.size(); i++) + { + cout << "Cluster " << i << endl; + cout << " X: " << clusters.at(i).X << endl; + cout << " Y: " << clusters.at(i).Y << endl; + cout << " E: " << clusters.at(i).E << endl; + cout << " subtype: " << clusters.at(i).subtype << endl; + cout << " type: " << clusters.at(i).type << endl; + cout << " istype: " << clusters.at(i).istype << endl; + cout << " T: " << clusters.at(i).T << endl; + cout << " N: " << clusters.at(i).N << endl; + cout << " nothing: " << clusters.at(i).nothing << endl; } + for(int i = 0; i < singletrigs.size(); i++) + { + cout << "Single Trigger " << i << endl; + cout << " T: " << singletrigs.at(i).T << endl; + cout << " emin: " << singletrigs.at(i).emin << endl; + cout << " emax: " << singletrigs.at(i).emax << endl; + cout << " nmin: " << singletrigs.at(i).nmin << endl; + cout << " xmin: " << singletrigs.at(i).xmin << endl; + cout << " pose: " << singletrigs.at(i).pose << endl; + cout << " hodo1c: " << singletrigs.at(i).hodo1c << endl; + cout << " hodo2c: " << singletrigs.at(i).hodo2c << endl; + cout << " hodogeo: " << singletrigs.at(i).hodogeo << endl; + cout << " hodoecal: " << singletrigs.at(i).hodoecal << endl; + cout << " topnbot: " << singletrigs.at(i).topnbot << endl; + cout << " inst: " << singletrigs.at(i).inst << endl; + cout << " subtype: " << singletrigs.at(i).subtype << endl; + cout << " type: " << singletrigs.at(i).type << endl; + cout << " istype: " << singletrigs.at(i).istype << endl; + } + for(int i = 0; i < pairtrigs.size(); i++) + { + cout << "Pair Trigger " << i << endl; + cout << " T: " << pairtrigs.at(i).T << endl; + cout << " clusesum: " << pairtrigs.at(i).clusesum << endl; + cout << " clusediff: " << pairtrigs.at(i).clusedif << endl; + cout << " eslope: " << pairtrigs.at(i).eslope << endl; + cout << " coplane: " << pairtrigs.at(i).coplane << endl; + cout << " dummy: " << pairtrigs.at(i).dummy << endl; + cout << " topnbot: " << pairtrigs.at(i).topnbot << endl; + cout << " inst: " << pairtrigs.at(i).inst << endl; + cout << " subtype: " << pairtrigs.at(i).subtype << endl; + cout << " type: " << pairtrigs.at(i).type << endl; + cout << " istype: " << pairtrigs.at(i).istype << endl; + } + for(int i = 0; i < calibtrigs.size(); i++) + { + cout << "Calibration Trigger " << i << endl; + cout << " T: " << calibtrigs.at(i).T << endl; + cout << " reserved: " << calibtrigs.at(i).reserved << endl; + cout << " cosmicTrig: " << calibtrigs.at(i).cosmicTrig << endl; + cout << " LEDTrig: " << calibtrigs.at(i).LEDTrig << endl; + cout << " hodoTrig: " << calibtrigs.at(i).hodoTrig << endl; + cout << " pulserTrig: " << calibtrigs.at(i).pulserTrig << endl; + cout << " subtype: " << calibtrigs.at(i).subtype << endl; + cout << " type: " << calibtrigs.at(i).type << endl; + cout << " istype: " << calibtrigs.at(i).istype << endl; + } + for(int i = 0; i < clustermult.size(); i++) + { + cout << "Cluster Multiplicty Trigger " << i << endl; + cout << " T: " << clustermult.at(i).T << endl; + cout << " multtop: " << clustermult.at(i).multtop << endl; + cout << " multbot: " << clustermult.at(i).multbot << endl; + cout << " multtot: " << clustermult.at(i).multtot << endl; + cout << " bitinst: " << clustermult.at(i).bitinst << endl; + cout << " subtype: " << clustermult.at(i).subtype << endl; + cout << " type: " << clustermult.at(i).type << endl; + cout << " istype: " << clustermult.at(i).istype << endl; + } + for(int i = 0; i < feetrigger.size(); i++) + { + cout << "FEE Trigger " << i << endl; + cout << " T: " << feetrigger.at(i).T << endl; + cout << " region: " << feetrigger.at(i).region << endl; + cout << " reserved: " << feetrigger.at(i).reserved << endl; + cout << " subtype: " << feetrigger.at(i).subtype << endl; + cout << " type: " << feetrigger.at(i).type << endl; + cout << " istype: " << feetrigger.at(i).istype << endl; + } + } + diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 6abd3ca22..7f462a7e8 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -13,81 +13,81 @@ Process::Process() {} //TODO Fix this better bool Process::processRootFiles() { - if ((input_files_[0]).find(".root") != std::string::npos) - return true; - - return false; + if ((input_files_[0]).find(".root") != std::string::npos) + return true; + + return false; } void Process::runOnRoot() { - try { - int n_events_processed = 0; - HpsEvent event; - int cfile =0 ; - for (auto ifile : input_files_) { - std::cout<<"Processing file"<setupEvent(&event); - } - for (auto module : sequence_) { - module->initialize(event.getTree()); - } - while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { - if (n_events_processed%1000 == 0) - std::cout<<"Event:"<process(&event); - } - //event.Clear(); - ++n_events_processed; - } - //Pass to next file - ++cfile; - // Finalize all modules - - //Select the output file for storing the results of the processors. - file->resetOutputFileDir(); - for (auto module : sequence_) { - //TODO:Change the finalize method - module->finalize(); - } - // TODO Check all these destructors - if (file) { - file->close(); - delete file; - file = nullptr; - } + try { + int n_events_processed = 0; + HpsEvent event; + int cfile =0 ; + for (auto ifile : input_files_) { + std::cout<<"Processing file"<setupEvent(&event); + } + for (auto module : sequence_) { + module->initialize(event.getTree()); + } + while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { + if (n_events_processed%1000 == 0) + std::cout<<"Event:"<process(&event); + } + //event.Clear(); + ++n_events_processed; + } + //Pass to next file + ++cfile; + // Finalize all modules + + //Select the output file for storing the results of the processors. + file->resetOutputFileDir(); + for (auto module : sequence_) { + //TODO:Change the finalize method + module->finalize(); + } + // TODO Check all these destructors + if (file) { + file->close(); + delete file; + file = nullptr; + } + } + } catch (std::exception& e) { + std::cerr<<"Error:"<initialize(tree); } - //In the case of additional output files from the processors this restores the correct ProcessID storage - file->resetOutputFileDir(); + //In the case of additional output files from the processors this restores the correct ProcessID storage + file->resetOutputFileDir(); // Process all events. while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { @@ -110,14 +110,14 @@ void Process::run() { std::cout << "---- [ hpstr ][ Process ]: Event: " << n_events_processed << std::endl; event.Clear(); for (auto module : sequence_) { - //TODO: actually pass the flag to the filling of the tree - if (!module->process(&event)) - break; + //TODO: actually pass the flag to the filling of the tree + if (!module->process(&event)) + break; } ++n_events_processed; } ++cfile; - + // Finalize all modules. for (auto module : sequence_) { module->finalize(); diff --git a/processors/include/EventProcessor.h b/processors/include/EventProcessor.h index 631c6dda0..2c5277743 100644 --- a/processors/include/EventProcessor.h +++ b/processors/include/EventProcessor.h @@ -30,6 +30,7 @@ #include "Collections.h" #include "EventHeader.h" #include "Processor.h" +#include "VTPData.h" #include "TriggerData.h" #include "Event.h" @@ -73,7 +74,9 @@ class EventProcessor : public Processor { private: TClonesArray* header_{nullptr}; + VTPData* vtpData{nullptr}; bool _debug{false}; + void parseVTPData(EVENT::LCGenericObject* vtp_data_lcio); }; // EventProcessor diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index d69a10641..adf689951 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -15,6 +15,8 @@ EventProcessor::~EventProcessor() { } void EventProcessor::initialize(TTree* tree) { + vtpData = new VTPData(); + tree->Branch(Collections::VTP_BANK, &vtpData); } bool EventProcessor::process(IEvent* ievent) { @@ -71,6 +73,7 @@ bool EventProcessor::process(IEvent* ievent) { = static_cast(ts_data->getElementAt(0)); header.setTriggerData(new TriggerData(vtp_datum, ts_datum)); + parseVTPData(vtp_datum); //header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); //header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); //header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); @@ -116,12 +119,165 @@ bool EventProcessor::process(IEvent* ievent) { // It's fine if the event doesn't have an RF hits collection. } + vtpData->print(); event->add(Collections::EVENT_HEADERS, &header); + event->add(Collections::VTP_BANK, vtpData); return true; } +void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) +{ + // First Clear out all the old data. + std::cout << "New VTP Block of size " << vtp_data_lcio->getNInt() << std::endl; + vtpData->Clear(); + for(int i=0; igetNInt()/2; ++i) + { + int data = vtp_data_lcio->getIntVal(i); + int secondWord = vtp_data_lcio->getIntVal(i+1); + if(!(data & 1<<31)) continue; + int type = (data>>27)&0x0F; + int subtype; + switch (type) + { + case 0: // Block Header + vtpData->blockHeader.blocklevel = (data )&0x00FF; + vtpData->blockHeader.blocknum = (data >> 8)&0x03FF; + vtpData->blockHeader.nothing = (data >> 18)&0x00FF; + vtpData->blockHeader.slotid = (data >> 22)&0x001F; + vtpData->blockHeader.type = (data >> 27)&0x000F; + vtpData->blockHeader.istype = (data >> 31)&0x0001; + std::cout << i << " BlockHeader " << vtpData->blockHeader.type << std::endl; + break; + case 1: // Block Tail + vtpData->blockTail.nwords = (data )&0x03FFFFF; + vtpData->blockTail.slotid = (data >> 22)&0x000001F; + vtpData->blockTail.type = (data >> 27)&0x000000F; + vtpData->blockTail.istype = (data >> 31)&0x0000001; + std::cout << i << " BlockTail " << vtpData->blockTail.type << std::endl; + break; + case 2: // Event Header + vtpData->eventHeader.eventnum = (data )&0x07FFFFFF; + vtpData->eventHeader.type = (data >> 27)&0x0000000F; + vtpData->eventHeader.istype = (data >> 31)&0x00000001; + std::cout << i << " EventHeader " << vtpData->eventHeader.eventnum << std::endl; + break; + case 3: // Trigger time + vtpData->trigTime = (data & 0x00FFFFFF) + ((secondWord & 0x00FFFFFF )<<24); + std::cout << i << "&" << i+1 << " trigTime = " << vtpData->trigTime << std::endl; + i++; + break; + case 12: // Expansion type + subtype = (data>>23)&0x0F; + switch(subtype){ + case 2: // HPS Cluster + VTPData::hpsCluster clus; + clus.X = (data )&0x0003F; + clus.Y = (data >> 6)&0x0000F; + clus.E = (data >> 10)&0x01FFF; + clus.subtype = (data >> 23)&0x0000F; + clus.type = (data >> 27)&0x0000F; + clus.istype = (data >> 31)&0x00001; + clus.T = (secondWord )&0x003FF; + clus.N = (secondWord >> 10)&0x0000F; + clus.nothing = (secondWord >> 14)&0x3FFFF; + vtpData->clusters.push_back(clus); + std::cout << i << "&" << i+1 << " HPS Cluster " << clus.E << std::endl; + i++; + break; + case 3: // HPS Single Trigger + VTPData::hpsSingleTrig strig; + strig.T = (data )&0x003FF; + strig.emin = (data >> 10)&0x00001; + strig.emax = (data >> 11)&0x00001; + strig.nmin = (data >> 12)&0x00001; + strig.xmin = (data >> 13)&0x00001; + strig.pose = (data >> 14)&0x00001; + strig.hodo1c = (data >> 15)&0x00001; + strig.hodo2c = (data >> 16)&0x00001; + strig.hodogeo = (data >> 17)&0x00001; + strig.hodoecal = (data >> 18)&0x00001; + strig.topnbot = (data >> 19)&0x00001; + strig.inst = (data >> 20)&0x00007; + strig.subtype = (data >> 23)&0x0000F; + strig.type = (data >> 27)&0x0000F; + strig.istype = (data >> 31)&0x00001; + std::cout << i << " HPS Single Trigger " << strig.subtype << std::endl; + vtpData->singletrigs.push_back(strig); + break; + case 4: // HPS Pair Trigger + VTPData::hpsPairTrig ptrig; + ptrig.T = (data )&0x003FF; + ptrig.clusesum = (data >> 10)&0x00001; + ptrig.clusedif = (data >> 11)&0x00001; + ptrig.eslope = (data >> 12)&0x00001; + ptrig.coplane = (data >> 13)&0x00001; + ptrig.dummy = (data >> 14)&0x0001F; + ptrig.topnbot = (data >> 19)&0x00001; + ptrig.inst = (data >> 20)&0x00007; + ptrig.subtype = (data >> 23)&0x0000F; + ptrig.type = (data >> 27)&0x0000F; + ptrig.istype = (data >> 31)&0x00001; + std::cout << i << " HPS Pair Trigger " << ptrig.subtype << std::endl; + vtpData->pairtrigs.push_back(ptrig); + break; + case 5: // HPS Calibration Trigger + VTPData::hpsCalibTrig ctrig; + ctrig.T = (data )&0x003FF; + ctrig.reserved = (data >> 10)&0x001FF; + ctrig.cosmicTrig = (data >> 19)&0x00001; + ctrig.LEDTrig = (data >> 20)&0x00001; + ctrig.hodoTrig = (data >> 21)&0x00001; + ctrig.pulserTrig = (data >> 22)&0x00001; + ctrig.subtype = (data >> 23)&0x0000F; + ctrig.type = (data >> 27)&0x0000F; + ctrig.istype = (data >> 31)&0x00001; + std::cout << i << " HPS Cal Trigger " << ctrig.subtype << std::endl; + vtpData->calibtrigs.push_back(ctrig); + break; + case 6: // HPS Cluster Multiplicity Trigger + VTPData::hpsClusterMult clmul; + clmul.T = (data )&0x003FF; + clmul.multtop = (data >> 10)&0x0000F; + clmul.multbot = (data >> 14)&0x0000F; + clmul.multtot = (data >> 18)&0x0000F; + clmul.bitinst = (data >> 22)&0x00001; + clmul.subtype = (data >> 23)&0x0000F; + clmul.type = (data >> 27)&0x0000F; + clmul.istype = (data >> 31)&0x00001; + std::cout << i << " HPS Clus Mult Trigger " << clmul.subtype << std::endl; + vtpData->clustermult.push_back(clmul); + break; + case 7: // HPS FEE Trigger + VTPData::hpsFEETrig fee; + fee.T = (data )&0x003FF; + fee.region = (data >> 10)&0x0007F; + fee.reserved = (data >> 17)&0x0003F; + fee.subtype = (data >> 23)&0x0000F; + fee.type = (data >> 27)&0x0000F; + fee.istype = (data >> 31)&0x00001; + std::cout << i << " HPS FEE Trigger " << fee.subtype << std::endl; + vtpData->feetrigger.push_back(fee); + break; + default: + std::cout << "At " << i << " invalid HPS type: " << type << " subtype: " << subtype << std::endl; + break; + } + + break; + case 14: + std::cout << i << "VTP data type not valid: " << type << std::endl; + break; + default: + std::cout << i << "I was not expecting a VTP data type of " << type << std::endl; + break; + } + } + std::cout << "---------------------------------------" << std::endl; + std::cout << std::endl; +} //VTPData::parseVTPData(LCGenericObject* vtp_data_lcio) + void EventProcessor::finalize() { } diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx index 940ff13ab..c7b5b9683 100644 --- a/processors/src/TrackingProcessor.cxx +++ b/processors/src/TrackingProcessor.cxx @@ -10,7 +10,7 @@ TrackingProcessor::~TrackingProcessor() { } void TrackingProcessor::initialize(TTree* tree) { - tree->Branch(Collections::GBL_TRACKS,&tracks_); + tree->Branch(Collections::GBL_TRACKS, &tracks_); tree->Branch(Collections::TRACKER_HITS, &hits_); tree->Branch(Collections::RAW_SVT_HITS, &rawhits_); From d09069459286fc0921a0f582f471bee9987bc139 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 8 Oct 2019 15:39:51 -0700 Subject: [PATCH 134/314] Adding TSData to event and parsing in EventHeaderProcessor --- event/include/EventLinkDef.h | 3 + event/include/TSData.h | 86 +++++++++++++++++++++++++++ event/src/TSData.cxx | 26 ++++++++ processors/include/EventProcessor.h | 3 + processors/src/EventProcessor.cxx | 92 ++++++++++++++++++++++++----- 5 files changed, 194 insertions(+), 16 deletions(-) create mode 100644 event/include/TSData.h create mode 100644 event/src/TSData.cxx diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 916111737..e3b6ce785 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -21,6 +21,8 @@ #pragma link C++ class VTPData::hpsClusterMult+; #pragma link C++ class VTPData::hpsFEETrig+; #pragma link C++ class TSData+; +#pragma link C++ class TSData::tsHeader+; +#pragma link C++ class TSData::tsBits+; #pragma link C++ class Particle+; #pragma link C++ class Track+; #pragma link C++ class Vertex+; @@ -44,4 +46,5 @@ #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; +#pragma link C++ class vector +; #endif diff --git a/event/include/TSData.h b/event/include/TSData.h new file mode 100644 index 000000000..53f350d14 --- /dev/null +++ b/event/include/TSData.h @@ -0,0 +1,86 @@ +/** + * @file TSData.h + * @brief Class used to decode TS words. + * @author: Maurik Holtrop, University of New Hampsire + * @author: Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef _TS_DATA_H_ +#define _TS_DATA_H_ + +#include + +//----------// +// LCIO // +//----------// +#include + +//----------// +// ROOT // +//----------// +#include + +class TSData : public TObject { + + public: + // tsHeader.type meaning: + // 0: Filler events + // 1-32: GTP Physics trigger; + // 33-64: Front panel physics trigger; + // 250: multi-hit on GTP or Front panel physics trigger + // 251: Multi-hit on GTP and Front panel physics trigger + // 253: VME trigger; + // 254: VME random trigger; + struct tsHeader + { + int wordCount; // 0-15 Event wordcount; Event header is excluded from the count + int test ; // 16-23 0000,0001, or 0x01 + int type ; // 24-31 Trigger Type + } header; + + struct tsBits + { + bool Single_0_Top ; // 0 ( 150-8191) MeV (-31,31) Low energy cluster + bool Single_1_Top ; // 1 ( 300-3000) MeV ( 5,31) e+ + bool Single_2_Top ; // 2 ( 300-3000) MeV ( 5,31) e+ : Position dependent energy cut + bool Single_3_Top ; // 3 ( 300-3000) MeV ( 5,31) e+ : HODO L1*L2 Match with cluster + bool Single_0_Bot ; // 4 ( 150-8191) MeV (-31,31) Low energy cluster + bool Single_1_Bot ; // 5 ( 300-3000) MeV ( 5,31) e+ + bool Single_2_Bot ; // 6 ( 300-3000) MeV ( 5,31) e+ : Position dependent energy cut + bool Single_3_Bot ; // 7 ( 300-3000) MeV ( 5,31) e+ : HODO L1*L2 Match with cluster + bool Pair_0 ; // 8 A' + bool Pair_1 ; // 9 Moller + bool Pair_2 ; // 10 pi0 + bool Pair_3 ; // 11 - + bool LED ; // 12 LED + bool Cosmic ; // 13 Cosmic + bool Hodoscope ; // 14 Hodoscope + bool Pulser ; // 15 Pulser + bool Mult_0 ; // 16 Multiplicity-0 2 Cluster Trigger + bool Mult_1 ; // 17 Multiplicity-1 3 Cluster trigger + bool FEE_Top ; // 18 FEE Top ( 2600-5200) + bool FEE_Bot ; // 19 FEE Bot ( 2600-5200) + unsigned int NA ; // 20-31 Not used + unsigned int intval; // Full word + }; + tsBits prescaled; + tsBits ext; + + unsigned long EN; // Event Number in Run + unsigned long T; // Trigger Time + + public: + TSData(); + ~TSData(); + + void print(); + + void Clear(){ + TObject::Clear(); + }; + + ClassDef(TSData, 1); + +}; + +#endif // __TS_DATA_H__ diff --git a/event/src/TSData.cxx b/event/src/TSData.cxx new file mode 100644 index 000000000..0f7ca491f --- /dev/null +++ b/event/src/TSData.cxx @@ -0,0 +1,26 @@ +/** + * @file TSData.cxx + * @brief Class used to decode VTP words. + * @author: Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#include "TSData.h" + +ClassImp(TSData) + +TSData::TSData() + : TObject() { + } + +TSData::~TSData(){ + Clear(); +} + +// TODO: Finish writing print method +void TSData::print(){ + using namespace std; + cout << "TSData::print()" << endl; + cout << "Event Number: " << EN << endl; + cout << "Trigger Time: " << T << endl; +} + diff --git a/processors/include/EventProcessor.h b/processors/include/EventProcessor.h index 2c5277743..fdfcbb612 100644 --- a/processors/include/EventProcessor.h +++ b/processors/include/EventProcessor.h @@ -31,6 +31,7 @@ #include "EventHeader.h" #include "Processor.h" #include "VTPData.h" +#include "TSData.h" #include "TriggerData.h" #include "Event.h" @@ -75,8 +76,10 @@ class EventProcessor : public Processor { TClonesArray* header_{nullptr}; VTPData* vtpData{nullptr}; + TSData* tsData{nullptr}; bool _debug{false}; void parseVTPData(EVENT::LCGenericObject* vtp_data_lcio); + void parseTSData(EVENT::LCGenericObject* ts_data_lcio); }; // EventProcessor diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index adf689951..0585f7b70 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -16,7 +16,9 @@ EventProcessor::~EventProcessor() { void EventProcessor::initialize(TTree* tree) { vtpData = new VTPData(); + tsData = new TSData(); tree->Branch(Collections::VTP_BANK, &vtpData); + tree->Branch(Collections::TS_BANK, &tsData); } bool EventProcessor::process(IEvent* ievent) { @@ -74,6 +76,7 @@ bool EventProcessor::process(IEvent* ievent) { header.setTriggerData(new TriggerData(vtp_datum, ts_datum)); parseVTPData(vtp_datum); + parseTSData(ts_datum); //header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); //header.setSingle1Trigger(static_cast(tdata->isSingle1Trigger())); //header.setPair0Trigger(static_cast(tdata->isPair0Trigger())); @@ -119,9 +122,8 @@ bool EventProcessor::process(IEvent* ievent) { // It's fine if the event doesn't have an RF hits collection. } - vtpData->print(); + //vtpData->print(); event->add(Collections::EVENT_HEADERS, &header); - event->add(Collections::VTP_BANK, vtpData); return true; @@ -130,7 +132,7 @@ bool EventProcessor::process(IEvent* ievent) { void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) { // First Clear out all the old data. - std::cout << "New VTP Block of size " << vtp_data_lcio->getNInt() << std::endl; + //std::cout << "New VTP Block of size " << vtp_data_lcio->getNInt() << std::endl; vtpData->Clear(); for(int i=0; igetNInt()/2; ++i) { @@ -148,24 +150,24 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) vtpData->blockHeader.slotid = (data >> 22)&0x001F; vtpData->blockHeader.type = (data >> 27)&0x000F; vtpData->blockHeader.istype = (data >> 31)&0x0001; - std::cout << i << " BlockHeader " << vtpData->blockHeader.type << std::endl; + //std::cout << i << " BlockHeader " << vtpData->blockHeader.type << std::endl; break; case 1: // Block Tail vtpData->blockTail.nwords = (data )&0x03FFFFF; vtpData->blockTail.slotid = (data >> 22)&0x000001F; vtpData->blockTail.type = (data >> 27)&0x000000F; vtpData->blockTail.istype = (data >> 31)&0x0000001; - std::cout << i << " BlockTail " << vtpData->blockTail.type << std::endl; + //std::cout << i << " BlockTail " << vtpData->blockTail.type << std::endl; break; case 2: // Event Header vtpData->eventHeader.eventnum = (data )&0x07FFFFFF; vtpData->eventHeader.type = (data >> 27)&0x0000000F; vtpData->eventHeader.istype = (data >> 31)&0x00000001; - std::cout << i << " EventHeader " << vtpData->eventHeader.eventnum << std::endl; + //std::cout << i << " EventHeader " << vtpData->eventHeader.eventnum << std::endl; break; case 3: // Trigger time vtpData->trigTime = (data & 0x00FFFFFF) + ((secondWord & 0x00FFFFFF )<<24); - std::cout << i << "&" << i+1 << " trigTime = " << vtpData->trigTime << std::endl; + //std::cout << i << "&" << i+1 << " trigTime = " << vtpData->trigTime << std::endl; i++; break; case 12: // Expansion type @@ -183,7 +185,7 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) clus.N = (secondWord >> 10)&0x0000F; clus.nothing = (secondWord >> 14)&0x3FFFF; vtpData->clusters.push_back(clus); - std::cout << i << "&" << i+1 << " HPS Cluster " << clus.E << std::endl; + //std::cout << i << "&" << i+1 << " HPS Cluster " << clus.E << std::endl; i++; break; case 3: // HPS Single Trigger @@ -203,7 +205,7 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) strig.subtype = (data >> 23)&0x0000F; strig.type = (data >> 27)&0x0000F; strig.istype = (data >> 31)&0x00001; - std::cout << i << " HPS Single Trigger " << strig.subtype << std::endl; + //std::cout << i << " HPS Single Trigger " << strig.subtype << std::endl; vtpData->singletrigs.push_back(strig); break; case 4: // HPS Pair Trigger @@ -219,7 +221,7 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) ptrig.subtype = (data >> 23)&0x0000F; ptrig.type = (data >> 27)&0x0000F; ptrig.istype = (data >> 31)&0x00001; - std::cout << i << " HPS Pair Trigger " << ptrig.subtype << std::endl; + //std::cout << i << " HPS Pair Trigger " << ptrig.subtype << std::endl; vtpData->pairtrigs.push_back(ptrig); break; case 5: // HPS Calibration Trigger @@ -233,7 +235,7 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) ctrig.subtype = (data >> 23)&0x0000F; ctrig.type = (data >> 27)&0x0000F; ctrig.istype = (data >> 31)&0x00001; - std::cout << i << " HPS Cal Trigger " << ctrig.subtype << std::endl; + //std::cout << i << " HPS Cal Trigger " << ctrig.subtype << std::endl; vtpData->calibtrigs.push_back(ctrig); break; case 6: // HPS Cluster Multiplicity Trigger @@ -246,7 +248,7 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) clmul.subtype = (data >> 23)&0x0000F; clmul.type = (data >> 27)&0x0000F; clmul.istype = (data >> 31)&0x00001; - std::cout << i << " HPS Clus Mult Trigger " << clmul.subtype << std::endl; + //std::cout << i << " HPS Clus Mult Trigger " << clmul.subtype << std::endl; vtpData->clustermult.push_back(clmul); break; case 7: // HPS FEE Trigger @@ -257,7 +259,7 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) fee.subtype = (data >> 23)&0x0000F; fee.type = (data >> 27)&0x0000F; fee.istype = (data >> 31)&0x00001; - std::cout << i << " HPS FEE Trigger " << fee.subtype << std::endl; + //std::cout << i << " HPS FEE Trigger " << fee.subtype << std::endl; vtpData->feetrigger.push_back(fee); break; default: @@ -274,9 +276,67 @@ void EventProcessor::parseVTPData(EVENT::LCGenericObject* vtp_data_lcio) break; } } - std::cout << "---------------------------------------" << std::endl; - std::cout << std::endl; -} //VTPData::parseVTPData(LCGenericObject* vtp_data_lcio) + //std::cout << "---------------------------------------" << std::endl; + //std::cout << std::endl; +} //EventProcessor::parseVTPData(LCGenericObject* vtp_data_lcio) + +void EventProcessor::parseTSData(EVENT::LCGenericObject* ts_data_lcio) +{ + // Parse out TS header + unsigned int headerWord = ts_data_lcio->getIntVal(1); + tsData->header.wordCount = (headerWord )&0xFFFF; // 0-15 Word Count + tsData->header.test = (headerWord >> 16)&0x00FF; // 16-23 Test Word + tsData->header.type = (headerWord >> 24)&0x00FF; // 24-31 Trigger Type + // Parse out trigger time and Event Number + tsData->T = static_cast(ts_data_lcio->getIntVal(3)) + ( (static_cast(ts_data_lcio->getIntVal(4)&0xFFFF)<<32)); + tsData->EN = static_cast(ts_data_lcio->getIntVal(2)) + ( (static_cast(ts_data_lcio->getIntVal(4)&0xFFFF0000)<<16)); + // Parse out prescaled word + tsData->prescaled.intval = ts_data_lcio->getIntVal(5); // Full word + tsData->prescaled.Single_0_Top = (tsData->prescaled.intval )&0x001; // 0 Low energy cluster + tsData->prescaled.Single_1_Top = (tsData->prescaled.intval >> 1)&0x001; // 1 e+ + tsData->prescaled.Single_2_Top = (tsData->prescaled.intval >> 2)&0x001; // 2 e+ : Position dependent energy cut + tsData->prescaled.Single_3_Top = (tsData->prescaled.intval >> 3)&0x001; // 3 e+ : HODO L1*L2 Match with cluster + tsData->prescaled.Single_0_Bot = (tsData->prescaled.intval >> 4)&0x001; // 4 Low energy cluster + tsData->prescaled.Single_1_Bot = (tsData->prescaled.intval >> 5)&0x001; // 5 e+ + tsData->prescaled.Single_2_Bot = (tsData->prescaled.intval >> 6)&0x001; // 6 e+ : Position dependent energy cut + tsData->prescaled.Single_3_Bot = (tsData->prescaled.intval >> 7)&0x001; // 7 e+ : HODO L1*L2 Match with cluster + tsData->prescaled.Pair_0 = (tsData->prescaled.intval >> 8)&0x001; // 8 A' + tsData->prescaled.Pair_1 = (tsData->prescaled.intval >> 9)&0x001; // 9 Moller + tsData->prescaled.Pair_2 = (tsData->prescaled.intval >> 10)&0x001; // 10 pi0 + tsData->prescaled.Pair_3 = (tsData->prescaled.intval >> 11)&0x001; // 11 - + tsData->prescaled.LED = (tsData->prescaled.intval >> 12)&0x001; // 12 LED + tsData->prescaled.Cosmic = (tsData->prescaled.intval >> 13)&0x001; // 13 Cosmic + tsData->prescaled.Hodoscope = (tsData->prescaled.intval >> 14)&0x001; // 14 Hodoscope + tsData->prescaled.Pulser = (tsData->prescaled.intval >> 15)&0x001; // 15 Pulser + tsData->prescaled.Mult_0 = (tsData->prescaled.intval >> 16)&0x001; // 16 Multiplicity-0 2 Cluster Trigger + tsData->prescaled.Mult_1 = (tsData->prescaled.intval >> 17)&0x001; // 17 Multiplicity-1 3 Cluster trigger + tsData->prescaled.FEE_Top = (tsData->prescaled.intval >> 18)&0x001; // 18 FEE Top ( 2600-5200) + tsData->prescaled.FEE_Bot = (tsData->prescaled.intval >> 19)&0x001; // 19 FEE Bot ( 2600-5200) + tsData->prescaled.NA = (tsData->prescaled.intval >> 20)&0xFFF; // 20-31 Not used + // Parse out ext word + tsData->ext.intval = ts_data_lcio->getIntVal(6); // Full word + tsData->ext.Single_0_Top = (tsData->ext.intval )&0x001; // 0 Low energy cluster + tsData->ext.Single_1_Top = (tsData->ext.intval >> 1)&0x001; // 1 e+ + tsData->ext.Single_2_Top = (tsData->ext.intval >> 2)&0x001; // 2 e+ : Position dependent energy cut + tsData->ext.Single_3_Top = (tsData->ext.intval >> 3)&0x001; // 3 e+ : HODO L1*L2 Match with cluster + tsData->ext.Single_0_Bot = (tsData->ext.intval >> 4)&0x001; // 4 Low energy cluster + tsData->ext.Single_1_Bot = (tsData->ext.intval >> 5)&0x001; // 5 e+ + tsData->ext.Single_2_Bot = (tsData->ext.intval >> 6)&0x001; // 6 e+ : Position dependent energy cut + tsData->ext.Single_3_Bot = (tsData->ext.intval >> 7)&0x001; // 7 e+ : HODO L1*L2 Match with cluster + tsData->ext.Pair_0 = (tsData->ext.intval >> 8)&0x001; // 8 A' + tsData->ext.Pair_1 = (tsData->ext.intval >> 9)&0x001; // 9 Moller + tsData->ext.Pair_2 = (tsData->ext.intval >> 10)&0x001; // 10 pi0 + tsData->ext.Pair_3 = (tsData->ext.intval >> 11)&0x001; // 11 - + tsData->ext.LED = (tsData->ext.intval >> 12)&0x001; // 12 LED + tsData->ext.Cosmic = (tsData->ext.intval >> 13)&0x001; // 13 Cosmic + tsData->ext.Hodoscope = (tsData->ext.intval >> 14)&0x001; // 14 Hodoscope + tsData->ext.Pulser = (tsData->ext.intval >> 15)&0x001; // 15 Pulser + tsData->ext.Mult_0 = (tsData->ext.intval >> 16)&0x001; // 16 Multiplicity-0 2 Cluster Trigger + tsData->ext.Mult_1 = (tsData->ext.intval >> 17)&0x001; // 17 Multiplicity-1 3 Cluster trigger + tsData->ext.FEE_Top = (tsData->ext.intval >> 18)&0x001; // 18 FEE Top ( 2600-5200) + tsData->ext.FEE_Bot = (tsData->ext.intval >> 19)&0x001; // 19 FEE Bot ( 2600-5200) + tsData->ext.NA = (tsData->ext.intval >> 20)&0xFFF; // 20-31 Not used +} //EventProcessor::parstsData->eTSData(LCGenericObject* ts_data_lcio) void EventProcessor::finalize() { } From 81bf9fbb4dbd6412c995c93afc2c049e42fd1996 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Wed, 9 Oct 2019 12:29:28 -0700 Subject: [PATCH 135/314] Minor cleanup after adding TS and VTP to EventProcessor --- analysis/include/HistoManager.h | 162 ++++---- analysis/src/ClusterHistos.cxx | 590 +++++++++++++++--------------- analysis/src/HistoManager.cxx | 336 ++++++++--------- analysis/src/TrackHistos.cxx | 278 +++++++------- event/include/EventHeader.h | 23 -- processors/src/EventProcessor.cxx | 1 - 6 files changed, 683 insertions(+), 707 deletions(-) diff --git a/analysis/include/HistoManager.h b/analysis/include/HistoManager.h index f2e711857..93798d0c2 100644 --- a/analysis/include/HistoManager.h +++ b/analysis/include/HistoManager.h @@ -12,87 +12,87 @@ class HistoManager { - public: - HistoManager() {m_name = "default";} - HistoManager(const std::string& inputName) {m_name=inputName;}; - - - virtual ~HistoManager(); - - TH3F* get3dHisto(const std::string& str) { - return histos3d[str]; - } - - TH2F* get2dHisto(const std::string& str) { - return histos2d[str]; - } - - TH1F* get1dHisto(const std::string& str) { - return histos1d[str]; - } - - TH1F* plot1D(const std::string& name,const std::string& xtitle, int nbinsX, float xmin, float xmax); - - TH1F* plot1D(const std::string& name,const std::string& xtitle, int nbinsX, double* axisX); - - TH2F* plot2D(std::string name, - std::string xtitle, int nbinsX, float xmin, float xmax, - std::string ytitle, int nbinsY, float ymin, float ymax); - - TH2F* plot2D(std::string name, - std::string xtitle, int nbinsX, double* axisX, - std::string ytitle, int nbinsY, double* axisY); - - TH2F* plot2D(std::string name, - std::string xtitle, int nbinsX, const double* axisX, - std::string ytitle, int nbinsY, const double* axisY); - - TH2F* plot2D(std::string name, - std::string xtitle, int nbinsX, double* axisX, - std::string ytitle, int nbinsY, float ymin, float ymax); - - TH3F* plot3D(std::string name, - std::string xtitle, int nbinsX, float xmin, float xmax, - std::string ytitle, int nbinsY, float ymin, float ymax, - std::string ztitle, int nbinsZ, float zmin, float zmax); - - - TH3F* plot3D(std::string name, - std::string xtitle, int nbinsX, double* axisX, - std::string ytitle, int nbinsY, double* axisY, - std::string ztitle, int nbinsZ, double* axisZ); - - - virtual void Define3DHistos(){}; - virtual void Define2DHistos(){}; - virtual void Define1DHistos(){}; - - - virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder = ""); - - virtual void saveHistos(TFile* outF = nullptr,std::string folder = ""); - - virtual void sumw2(); - - void debugMode(bool debug) {debug_ = debug;} - - protected: - - std::string m_name; - - std::map > Axes; - - std::map histos1d; - typedef std::map::iterator it1d; - - std::map histos2d; - typedef std::map::iterator it2d; - - std::map histos3d; - typedef std::map::iterator it3d; - - bool debug_{false}; - + public: + HistoManager() {m_name = "default";} + HistoManager(const std::string& inputName) {m_name=inputName;}; + + + virtual ~HistoManager(); + + TH3F* get3dHisto(const std::string& str) { + return histos3d[str]; + } + + TH2F* get2dHisto(const std::string& str) { + return histos2d[str]; + } + + TH1F* get1dHisto(const std::string& str) { + return histos1d[str]; + } + + TH1F* plot1D(const std::string& name,const std::string& xtitle, int nbinsX, float xmin, float xmax); + + TH1F* plot1D(const std::string& name,const std::string& xtitle, int nbinsX, double* axisX); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, const double* axisX, + std::string ytitle, int nbinsY, const double* axisY); + + TH2F* plot2D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, float ymin, float ymax); + + TH3F* plot3D(std::string name, + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax, + std::string ztitle, int nbinsZ, float zmin, float zmax); + + + TH3F* plot3D(std::string name, + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY, + std::string ztitle, int nbinsZ, double* axisZ); + + + virtual void Define3DHistos(){}; + virtual void Define2DHistos(){}; + virtual void Define1DHistos(){}; + + + virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder = ""); + + virtual void saveHistos(TFile* outF = nullptr,std::string folder = ""); + + virtual void sumw2(); + + void debugMode(bool debug) {debug_ = debug;} + + protected: + + std::string m_name; + + std::map > Axes; + + std::map histos1d; + typedef std::map::iterator it1d; + + std::map histos2d; + typedef std::map::iterator it2d; + + std::map histos3d; + typedef std::map::iterator it3d; + + bool debug_{false}; + }; diff --git a/analysis/src/ClusterHistos.cxx b/analysis/src/ClusterHistos.cxx index 31900bf74..28801d23d 100644 --- a/analysis/src/ClusterHistos.cxx +++ b/analysis/src/ClusterHistos.cxx @@ -3,204 +3,204 @@ #include "TCanvas.h" ClusterHistos::ClusterHistos(const std::string& inputName):HistoManager(inputName) { - m_name = inputName; - mmapper_ = new ModuleMapper(2019); + m_name = inputName; + mmapper_ = new ModuleMapper(2019); } ClusterHistos::~ClusterHistos() { - - std::cout<<"Cleaning ClusterHistos"<::iterator it = baselineGraphs.begin(); - it!=baselineGraphs.end(); ++it) { - if (it->second) { - delete (it->second); - it->second = nullptr; + + std::cout<<"Cleaning ClusterHistos"<::iterator it = baselineGraphs.begin(); + it!=baselineGraphs.end(); ++it) { + if (it->second) { + delete (it->second); + it->second = nullptr; + } } - } - baselineGraphs.clear(); + baselineGraphs.clear(); } void ClusterHistos::Define1DHistos() { - //TODO improve this naming scheme - std::string h_name = ""; - - //Cluster position - histos1d[m_name+"_gz"] = plot1D(m_name+"_gz","Global Z [mm]",20000,-1000,2000); - - mmapper_->getStrings(half_module_names); - - for (unsigned int ihm = 0; ihmgetStrings(half_module_names); + + for (unsigned int ihm = 0; ihmGetDirectory("baseline"); - - TList* keyList = dir->GetListOfKeys(); - TIter next(keyList); - TKey* key; - - //I assume that there are only TGraphErrors - //TObject* obj; - - while ( (key = (TKey*)next())) { - //obj = key->ReadObj(); - //if (strcmp(obj->IsA()->GetName(),"TGraphErrors") != 0 ) - //continue; - - - //x values go from 0 to 512 (513 points) for L0-1. Last point is 0 - //x values go from 0 to 639 (640 points) for other layers - std::string graph_key = key->GetName(); - graph_key = graph_key.substr(graph_key.find("F"),4); - baselineGraphs[graph_key] = (TGraphErrors*) (dir->Get(key->GetName())); - } - - //for (std::map::iterator it = baselineGraphs.begin(); it!=baselineGraphs.end(); ++it) - //std::cout<first<<" " <second->GetN()<GetN();point++) { - //Double_t x=-999; - //Double_t y=-999; - //baselineGraphs["F5H1"]->GetPoint(point,x,y); - //std::cout<Close(); - delete baselinesFile; - baselinesFile = nullptr; - - return true; + + baselineRun_ = baselineRun; + + + TFile *baselinesFile = new TFile((baselineFits_+"/hpssvt_"+baselineRun+"_baselineFits.root").c_str()); + + if (!baselinesFile) + return false; + + TDirectory* dir = baselinesFile->GetDirectory("baseline"); + + TList* keyList = dir->GetListOfKeys(); + TIter next(keyList); + TKey* key; + + //I assume that there are only TGraphErrors + //TObject* obj; + + while ( (key = (TKey*)next())) { + //obj = key->ReadObj(); + //if (strcmp(obj->IsA()->GetName(),"TGraphErrors") != 0 ) + //continue; + + + //x values go from 0 to 512 (513 points) for L0-1. Last point is 0 + //x values go from 0 to 639 (640 points) for other layers + std::string graph_key = key->GetName(); + graph_key = graph_key.substr(graph_key.find("F"),4); + baselineGraphs[graph_key] = (TGraphErrors*) (dir->Get(key->GetName())); + } + + //for (std::map::iterator it = baselineGraphs.begin(); it!=baselineGraphs.end(); ++it) + //std::cout<first<<" " <second->GetN()<GetN();point++) { + //Double_t x=-999; + //Double_t y=-999; + //baselineGraphs["F5H1"]->GetPoint(point,x,y); + //std::cout<Close(); + delete baselinesFile; + baselinesFile = nullptr; + + return true; } @@ -209,118 +209,118 @@ bool ClusterHistos::LoadBaselineHistos(const std::string& baselineRun) { void ClusterHistos::FillHistograms(TrackerHit* hit,float weight) { - TRefArray* rawhits_ = hit->getRawHits(); - //int iv = -1; // 0 top, 1 bottom - //int it = -1; // 0 axial, 1 stereo - //int ily = -1; // 0-6 - - //TODO do this better - - //std::cout<<"Size:" <GetEntries()<GetEntries(); ++irh) { - - RawSvtHit * rawhit = static_cast(rawhits_->At(irh)); - //rawhit layers go from 1 to 14. Example: RawHit->Layer1 is layer0 axial on top and layer0 stereo in bottom. - - swTag = "ly"+std::to_string(rawhit->getLayer())+"_m"+std::to_string(rawhit->getModule()); - - std::string key = mmapper_->getStringFromSw(swTag); - //std::cout<<"----"<getStringFromSw(swTag)<getAmp(); - - double baseline = -999; - double strip = -999; - - //2D cluster corrected charge - if (baselineGraphs[mmapper_->getHwFromString(key)]) - baselineGraphs[mmapper_->getHwFromString(key)]->GetPoint(rawhit->getStrip(),strip,baseline); - - float sample0 = baseline - rawhit->getADCs()[0]; - float sample1 = baseline - rawhit->getADCs()[1]; - - chargeCorrectedMap[m_name+"_"+key+"_charge"] += (rawhit->getAmp() + sample0); - - histos2d[m_name+"_"+key+"_sample0_vs_Amp"]->Fill(rawhit->getAmp(),sample0,weight); - histos2d[m_name+"_"+key+"_sample1_vs_Amp"]->Fill(rawhit->getAmp(),sample1,weight); - - histos2d[m_name+"_"+key+"_sample0_vs_stripPos"]->Fill(rawhit->getStrip(),-sample0,weight); - histos2d[m_name+"_"+key+"_sample1_vs_stripPos"]->Fill(rawhit->getStrip(),-sample1,weight); - - - //2D cluster size1 - cluSizeMap [m_name+"_"+key+"_cluSize"] ++; - - //2D Weighted position numerator - cluPositionMap[m_name+"_"+key+"_charge"] += rawhit->getAmp()*rawhit->getStrip(); - //std::cout<<"rawhit->getStrip()::"<getStrip()<::iterator it = cluSizeMap.begin(); it!=cluSizeMap.end(); ++it ) { - if (it->second != 0) { - //std::cout<<"Filling..."<first<<" "<first]<first]->Fill(it->second,weight); - cluSizeMap[it->first]= 0; + TRefArray* rawhits_ = hit->getRawHits(); + //int iv = -1; // 0 top, 1 bottom + //int it = -1; // 0 axial, 1 stereo + //int ily = -1; // 0-6 + + //TODO do this better + + //std::cout<<"Size:" <GetEntries()<GetEntries(); ++irh) { + + RawSvtHit * rawhit = static_cast(rawhits_->At(irh)); + //rawhit layers go from 1 to 14. Example: RawHit->Layer1 is layer0 axial on top and layer0 stereo in bottom. + + swTag = "ly"+std::to_string(rawhit->getLayer())+"_m"+std::to_string(rawhit->getModule()); + + std::string key = mmapper_->getStringFromSw(swTag); + //std::cout<<"----"<getStringFromSw(swTag)<getAmp(); + + double baseline = -999; + double strip = -999; + + //2D cluster corrected charge + if (baselineGraphs[mmapper_->getHwFromString(key)]) + baselineGraphs[mmapper_->getHwFromString(key)]->GetPoint(rawhit->getStrip(),strip,baseline); + + float sample0 = baseline - rawhit->getADCs()[0]; + float sample1 = baseline - rawhit->getADCs()[1]; + + chargeCorrectedMap[m_name+"_"+key+"_charge"] += (rawhit->getAmp() + sample0); + + histos2d[m_name+"_"+key+"_sample0_vs_Amp"]->Fill(rawhit->getAmp(),sample0,weight); + histos2d[m_name+"_"+key+"_sample1_vs_Amp"]->Fill(rawhit->getAmp(),sample1,weight); + + histos2d[m_name+"_"+key+"_sample0_vs_stripPos"]->Fill(rawhit->getStrip(),-sample0,weight); + histos2d[m_name+"_"+key+"_sample1_vs_stripPos"]->Fill(rawhit->getStrip(),-sample1,weight); + + + //2D cluster size1 + cluSizeMap [m_name+"_"+key+"_cluSize"] ++; + + //2D Weighted position numerator + cluPositionMap[m_name+"_"+key+"_charge"] += rawhit->getAmp()*rawhit->getStrip(); + //std::cout<<"rawhit->getStrip()::"<getStrip()<::iterator it = cluSizeMap.begin(); it!=cluSizeMap.end(); ++it ) { + if (it->second != 0) { + //std::cout<<"Filling..."<first<<" "<first]<first]->Fill(it->second,weight); + cluSizeMap[it->first]= 0; + } + }// fills the maps + + //TODO make this more efficient: useless to loop all over the possibilities + for (std::map::iterator it = chargeMap.begin(); it!=chargeMap.end(); ++it ) { + //TODO make it better + //Avoid comparing to 0.0 and check if there is a charge deposit on this + if (it->second > 1e-6) { + + + std::string plotID = (it->first).substr(0,(it->first).find("_charge")); + + //it->second holds the charge + //it->first = charge histogram name. + double charge = it->second; + histos1d[it->first]->Fill(charge,weight); + double weighted_pos = cluPositionMap[it->first] / (charge); + double chargeCorrected = chargeCorrectedMap[it->first]; + //std::cout<<"weighted pos "<first+"_vs_stripPos"]->Fill(weighted_pos,charge,weight); + + // Fill the baseline corrected charge + histos2d[it->first+"_corrected_vs_stripPos"]->Fill(weighted_pos,chargeCorrected,weight); + + //Fill local vs global + + histos2d[plotID+"_stripPos_vs_gy"]->Fill(fabs(hit->getGlobalY()),weighted_pos,weight); + + double globRad = sqrt(hit->getGlobalX() * hit->getGlobalX() + hit->getGlobalY()+hit->getGlobalY()); + histos2d[it->first+"_vs_globRad"]->Fill(globRad,charge,weight); + + + chargeMap[it->first] = 0.0; + chargeCorrectedMap[it->first] = 0.0; + cluPositionMap[it->first] = 0.0; + + } + } + histos1d[m_name+"_gz"]->Fill(hit->getGlobalZ(),weight); + //1D + //histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); + //2D + if (hit->getGlobalZ() < 50 && hit->getGlobalZ() > 40) { + histos2d[m_name+"_gy_L0T_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight); + histos2d[m_name+"_charge_L0T_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0T_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); + + } + + if (hit->getGlobalZ() < 60 && hit->getGlobalZ() > 55) { + histos2d[m_name+"_gy_L0B_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight); + histos2d[m_name+"_charge_L0B_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); + histos2d[m_name+"_charge_L0B_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); } - }// fills the maps - - //TODO make this more efficient: useless to loop all over the possibilities - for (std::map::iterator it = chargeMap.begin(); it!=chargeMap.end(); ++it ) { - //TODO make it better - //Avoid comparing to 0.0 and check if there is a charge deposit on this - if (it->second > 1e-6) { - - - std::string plotID = (it->first).substr(0,(it->first).find("_charge")); - - //it->second holds the charge - //it->first = charge histogram name. - double charge = it->second; - histos1d[it->first]->Fill(charge,weight); - double weighted_pos = cluPositionMap[it->first] / (charge); - double chargeCorrected = chargeCorrectedMap[it->first]; - //std::cout<<"weighted pos "<first+"_vs_stripPos"]->Fill(weighted_pos,charge,weight); - - // Fill the baseline corrected charge - histos2d[it->first+"_corrected_vs_stripPos"]->Fill(weighted_pos,chargeCorrected,weight); - - //Fill local vs global - - histos2d[plotID+"_stripPos_vs_gy"]->Fill(fabs(hit->getGlobalY()),weighted_pos,weight); - - double globRad = sqrt(hit->getGlobalX() * hit->getGlobalX() + hit->getGlobalY()+hit->getGlobalY()); - histos2d[it->first+"_vs_globRad"]->Fill(globRad,charge,weight); - - - chargeMap[it->first] = 0.0; - chargeCorrectedMap[it->first] = 0.0; - cluPositionMap[it->first] = 0.0; - - } - } - histos1d[m_name+"_gz"]->Fill(hit->getGlobalZ(),weight); - //1D - //histos1d[m_name+"_charge"]->Fill(hit->getCharge(),weight); - //2D - if (hit->getGlobalZ() < 50 && hit->getGlobalZ() > 40) { - histos2d[m_name+"_gy_L0T_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight); - histos2d[m_name+"_charge_L0T_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); - histos2d[m_name+"_charge_L0T_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); - - } - - if (hit->getGlobalZ() < 60 && hit->getGlobalZ() > 55) { - histos2d[m_name+"_gy_L0B_vs_gx"]->Fill(hit->getGlobalX(),fabs(hit->getGlobalY()),weight); - histos2d[m_name+"_charge_L0B_vs_gx"]->Fill(hit->getGlobalX(),hit->getCharge(),weight); - histos2d[m_name+"_charge_L0B_vs_gy"]->Fill(fabs(hit->getGlobalY()),hit->getCharge(),weight); - } } diff --git a/analysis/src/HistoManager.cxx b/analysis/src/HistoManager.cxx index 1da589948..44fbaf565 100644 --- a/analysis/src/HistoManager.cxx +++ b/analysis/src/HistoManager.cxx @@ -5,231 +5,231 @@ HistoManager::~HistoManager() { - - std::cout<<"Cleaning up HistoManager"<second) { - delete (it->second); - (it->second) = nullptr; + + std::cout<<"Cleaning up HistoManager"<second) { + delete (it->second); + (it->second) = nullptr; + } } - } - histos1d.clear(); - - for (it2d it = histos2d.begin(); it!=histos2d.end(); ++it) { - if (it->second) { - delete (it->second); - (it->second) = nullptr; + histos1d.clear(); + + for (it2d it = histos2d.begin(); it!=histos2d.end(); ++it) { + if (it->second) { + delete (it->second); + (it->second) = nullptr; + } } - } - histos2d.clear(); - - for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { - if (it->second) { - delete (it->second); - (it->second) = nullptr; + histos2d.clear(); + + for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { + if (it->second) { + delete (it->second); + (it->second) = nullptr; + } } - } - histos3d.clear(); + histos3d.clear(); } void HistoManager::GetHistosFromFile(TFile* inFile, const std::string& name, const std::string& folder) { - - //Todo: use name as regular expression. - //Todo: use folder to choose a folder. - TIter next(inFile->GetListOfKeys()); - TKey *key; - while ((key = (TKey*)next())) { - std::string classType = key->GetClassName(); - if (classType.find("TH1")!=std::string::npos) - histos1d[key->GetName()] = (TH1F*) key->ReadObj(); - if (classType.find("TH2")!=std::string::npos) - histos2d[key->GetName()] = (TH2F*) key->ReadObj(); - if (classType.find("TH3")!=std::string::npos) - histos3d[key->GetName()] = (TH3F*) key->ReadObj(); - } + + //Todo: use name as regular expression. + //Todo: use folder to choose a folder. + TIter next(inFile->GetListOfKeys()); + TKey *key; + while ((key = (TKey*)next())) { + std::string classType = key->GetClassName(); + if (classType.find("TH1")!=std::string::npos) + histos1d[key->GetName()] = (TH1F*) key->ReadObj(); + if (classType.find("TH2")!=std::string::npos) + histos2d[key->GetName()] = (TH2F*) key->ReadObj(); + if (classType.find("TH3")!=std::string::npos) + histos3d[key->GetName()] = (TH3F*) key->ReadObj(); + } } TH1F* HistoManager::plot1D(const std::string& name,const std::string& xtitle, int nbinsX, float xmin, float xmax) { - TH1F* h= new TH1F(name.c_str(),name.c_str(),nbinsX,xmin,xmax); - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->Sumw2(); - return h; + TH1F* h= new TH1F(name.c_str(),name.c_str(),nbinsX,xmin,xmax); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->Sumw2(); + return h; } TH1F* HistoManager::plot1D(const std::string& name,const std::string& xtitle, int nbinsX, double* axisX) { - TH1F* h= new TH1F(name.c_str(),name.c_str(),nbinsX,axisX); - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->Sumw2(); - return h; + TH1F* h= new TH1F(name.c_str(),name.c_str(),nbinsX,axisX); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->Sumw2(); + return h; } TH2F* HistoManager::plot2D(std::string name, - std::string xtitle, int nbinsX, float xmin, float xmax, - std::string ytitle, int nbinsY, float ymin, float ymax) { - - TH2F* h = new TH2F(name.c_str(),name.c_str(), - nbinsX,xmin,xmax, - nbinsY,ymin,ymax); - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->GetYaxis()->SetTitle(ytitle.c_str()); - h->Sumw2(); - return h; + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax) { + + TH2F* h = new TH2F(name.c_str(),name.c_str(), + nbinsX,xmin,xmax, + nbinsY,ymin,ymax); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; } TH2F* HistoManager::plot2D(std::string name, - std::string xtitle, int nbinsX, double* axisX, - std::string ytitle, int nbinsY, double* axisY) { - - TH2F * h = new TH2F(name.c_str(),name.c_str(), - nbinsX,axisX, - nbinsY,axisY); - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->GetYaxis()->SetTitle(ytitle.c_str()); - h->Sumw2(); - return h; + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY) { + + TH2F * h = new TH2F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,axisY); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; } TH2F* HistoManager::plot2D(std::string name, - std::string xtitle, int nbinsX, const double* axisX, - std::string ytitle, int nbinsY, const double* axisY) { - - TH2F * h = new TH2F(name.c_str(),name.c_str(), - nbinsX,axisX, - nbinsY,axisY); - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->GetYaxis()->SetTitle(ytitle.c_str()); - h->Sumw2(); - return h; + std::string xtitle, int nbinsX, const double* axisX, + std::string ytitle, int nbinsY, const double* axisY) { + + TH2F * h = new TH2F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,axisY); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; } TH2F* HistoManager::plot2D(std::string name, - std::string xtitle, int nbinsX, double* axisX, - std::string ytitle, int nbinsY, float ymin, float ymax) { - - TH2F * h = new TH2F(name.c_str(),name.c_str(), - nbinsX,axisX, - nbinsY,ymin,ymax); - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->GetYaxis()->SetTitle(ytitle.c_str()); - h->Sumw2(); - return h; + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, float ymin, float ymax) { + + TH2F * h = new TH2F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,ymin,ymax); + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->Sumw2(); + return h; } TH3F* HistoManager::plot3D(std::string name, - std::string xtitle, int nbinsX, double* axisX, - std::string ytitle, int nbinsY, double* axisY, - std::string ztitle, int nbinsZ, double* axisZ) { - - - TH3F* h = new TH3F(name.c_str(),name.c_str(), - nbinsX,axisX, - nbinsY,axisY, - nbinsZ,axisZ); - - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->GetYaxis()->SetTitle(ytitle.c_str()); - h->GetZaxis()->SetTitle(ztitle.c_str()); - h->Sumw2(); - return h; + std::string xtitle, int nbinsX, double* axisX, + std::string ytitle, int nbinsY, double* axisY, + std::string ztitle, int nbinsZ, double* axisZ) { + + + TH3F* h = new TH3F(name.c_str(),name.c_str(), + nbinsX,axisX, + nbinsY,axisY, + nbinsZ,axisZ); + + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->GetZaxis()->SetTitle(ztitle.c_str()); + h->Sumw2(); + return h; } TH3F* HistoManager::plot3D(std::string name, - std::string xtitle, int nbinsX, float xmin, float xmax, - std::string ytitle, int nbinsY, float ymin, float ymax, - std::string ztitle, int nbinsZ, float zmin, float zmax) { - - - TH3F* h = new TH3F(name.c_str(),name.c_str(), - nbinsX,xmin,xmax, - nbinsY,ymin,ymax, - nbinsZ,zmin,zmax); - - h->GetXaxis()->SetTitle(xtitle.c_str()); - h->GetYaxis()->SetTitle(ytitle.c_str()); - h->GetZaxis()->SetTitle(ztitle.c_str()); - h->Sumw2(); - return h; + std::string xtitle, int nbinsX, float xmin, float xmax, + std::string ytitle, int nbinsY, float ymin, float ymax, + std::string ztitle, int nbinsZ, float zmin, float zmax) { + + + TH3F* h = new TH3F(name.c_str(),name.c_str(), + nbinsX,xmin,xmax, + nbinsY,ymin,ymax, + nbinsZ,zmin,zmax); + + h->GetXaxis()->SetTitle(xtitle.c_str()); + h->GetYaxis()->SetTitle(ytitle.c_str()); + h->GetZaxis()->SetTitle(ztitle.c_str()); + h->Sumw2(); + return h; } void HistoManager::sumw2() { - for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { - if (!it->second){ - std::cout<first<<" Null ptr in saving.."<second){ + std::cout<first<<" Null ptr in saving.."<second->Sumw2(); } - it->second->Sumw2(); - } - - for (it2d it = histos2d.begin(); it!=histos2d.end(); ++it) { - if (!(it->second)) { - std::cout<first<<" Null ptr in saving.."<second)) { + std::cout<first<<" Null ptr in saving.."<second->Sumw2(); } - it->second->Sumw2(); - } - - for (it1d it = histos1d.begin(); it!=histos1d.end(); ++it) { - if (!it->second){ - std::cout<first<<" Null ptr in saving.."<second){ + std::cout<first<<" Null ptr in saving.."<second->Sumw2(); } - it->second->Sumw2(); - } - + } void HistoManager::saveHistos(TFile* outF,std::string folder) { - if (outF) - outF->cd(); - TDirectoryFile* dir = 0; - - if (!folder.empty()) { - dir = new TDirectoryFile(folder.c_str(),folder.c_str()); - dir->cd(); - } - - for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { - if (!it->second){ - std::cout<first<<" Null ptr in saving.."<cd(); + TDirectoryFile* dir = 0; + + if (!folder.empty()) { + dir = new TDirectoryFile(folder.c_str(),folder.c_str()); + dir->cd(); } - it->second->Write(); - } - - for (it2d it = histos2d.begin(); it!=histos2d.end(); ++it) { - if (!(it->second)) { - std::cout<first<<" Null ptr in saving.."<second){ + std::cout<first<<" Null ptr in saving.."<second->Write(); } - it->second->Write(); - } - - for (it1d it = histos1d.begin(); it!=histos1d.end(); ++it) { - if (!it->second){ - std::cout<first<<" Null ptr in saving.."<second)) { + std::cout<first<<" Null ptr in saving.."<second->Write(); + } + + for (it1d it = histos1d.begin(); it!=histos1d.end(); ++it) { + if (!it->second){ + std::cout<first<<" Null ptr in saving.."<second->Write(); } - it->second->Write(); - } - - if (dir) {delete dir; dir=0;} - + + if (dir) {delete dir; dir=0;} + } diff --git a/analysis/src/TrackHistos.cxx b/analysis/src/TrackHistos.cxx index 25b4c293f..e62c8b1bc 100644 --- a/analysis/src/TrackHistos.cxx +++ b/analysis/src/TrackHistos.cxx @@ -2,50 +2,50 @@ #include void TrackHistos::Define1DHistos() { - - //TODO improve naming - std::string h_name = ""; - - for (unsigned int itp = 0; itpGetXaxis()->SetBinLabel(i,labels[i-1].c_str()); - - histos1d[m_name+"_type" ] = plot1D(m_name+"_type", - "Type",64,0,64); - - histos1d[m_name+"_nShared"] = plot1D(m_name+"_nShared", - "nShared Hits",8,-0.5,7.5); - histos1d[m_name+"_sharingHits"] = plot1D(m_name+"_sharingHits", - "sharingHits",6,-0.5,5.5); - - labels[0]="All Tracks"; - labels[1]="nShared = 0"; - labels[2]="SharedLy0"; - labels[3]="SharedLy1"; - labels[4]="SharedLy0AndLy1"; - labels[5]="Shared Others"; - - - for (int i = 1; i<=nbinsX; ++i) - histos1d[m_name+"_sharingHits"]->GetXaxis()->SetBinLabel(i,labels[i-1].c_str()); - - - //Hit content - //shared hits - //location of hit in first layer - //Total charge of hit in first layer - //size of hit in first layer + + //TODO improve naming + std::string h_name = ""; + + for (unsigned int itp = 0; itpGetXaxis()->SetBinLabel(i,labels[i-1].c_str()); + + histos1d[m_name+"_type" ] = plot1D(m_name+"_type", + "Type",64,0,64); + + histos1d[m_name+"_nShared"] = plot1D(m_name+"_nShared", + "nShared Hits",8,-0.5,7.5); + histos1d[m_name+"_sharingHits"] = plot1D(m_name+"_sharingHits", + "sharingHits",6,-0.5,5.5); + + labels[0]="All Tracks"; + labels[1]="nShared = 0"; + labels[2]="SharedLy0"; + labels[3]="SharedLy1"; + labels[4]="SharedLy0AndLy1"; + labels[5]="Shared Others"; + + + for (int i = 1; i<=nbinsX; ++i) + histos1d[m_name+"_sharingHits"]->GetXaxis()->SetBinLabel(i,labels[i-1].c_str()); + + + //Hit content + //shared hits + //location of hit in first layer + //Total charge of hit in first layer + //size of hit in first layer @@ -54,120 +54,120 @@ void TrackHistos::Define1DHistos() { void TrackHistos::BuildAxes() { - axes["d0"].push_back(200); - axes["d0"].push_back(-10); - axes["d0"].push_back(10); + axes["d0"].push_back(200); + axes["d0"].push_back(-10); + axes["d0"].push_back(10); - axes["Phi"].push_back(100); - axes["Phi"].push_back(-0.5); - axes["Phi"].push_back(0.5); + axes["Phi"].push_back(100); + axes["Phi"].push_back(-0.5); + axes["Phi"].push_back(0.5); - axes["Omega"].push_back(100); - axes["Omega"].push_back(-0.002); - axes["Omega"].push_back(0.002); + axes["Omega"].push_back(100); + axes["Omega"].push_back(-0.002); + axes["Omega"].push_back(0.002); - axes["TanLambda"].push_back(200); - axes["TanLambda"].push_back(-0.6); - axes["TanLambda"].push_back(0.6); + axes["TanLambda"].push_back(200); + axes["TanLambda"].push_back(-0.6); + axes["TanLambda"].push_back(0.6); - axes["Z0"].push_back(200); - axes["Z0"].push_back(-20); - axes["Z0"].push_back(20); + axes["Z0"].push_back(200); + axes["Z0"].push_back(-20); + axes["Z0"].push_back(20); - axes["time"].push_back(200); - axes["time"].push_back(-10); - axes["time"].push_back(10); + axes["time"].push_back(200); + axes["time"].push_back(-10); + axes["time"].push_back(10); - axes["chi2"].push_back(200); - axes["chi2"].push_back(0); - axes["chi2"].push_back(30); + axes["chi2"].push_back(200); + axes["chi2"].push_back(0); + axes["chi2"].push_back(30); } void TrackHistos::Define2DHistos() { - - //TODO improve naming - std::string h_name = ""; - - //TODO improve binning - if (doTrkCompPlots) { - - for (unsigned int itp = 0; itpFill(track->getD0() ,weight); - histos1d[m_name+"_Phi" ]->Fill(track->getPhi() ,weight); - histos1d[m_name+"_Omega" ]->Fill(track->getOmega() ,weight); - histos1d[m_name+"_TanLambda"]->Fill(track->getTanLambda() ,weight); - histos1d[m_name+"_Z0" ]->Fill(track->getZ0() ,weight); - histos1d[m_name+"_time" ]->Fill(track->getTrackTime() ,weight); - histos1d[m_name+"_chi2" ]->Fill(track->getChi2Ndf() ,weight); - histos1d[m_name+"_nShared" ]->Fill(track->getNShared() ,weight); - - //All Tracks - histos1d[m_name+"_sharingHits"]->Fill(0.,weight); - if (track->getNShared() == 0) - histos1d[m_name+"_sharingHits"]->Fill(1.,weight); - else { - //track has shared hits - if (track->getSharedLy0()) - histos1d[m_name+"_sharingHits"]->Fill(2.,weight); - if (track->getSharedLy1()) - histos1d[m_name+"_sharingHits"]->Fill(3.,weight); - if (track->getSharedLy0() && track->getSharedLy1()) - histos1d[m_name+"_sharingHits"]->Fill(4.,weight); - if (!track->getSharedLy0() && !track->getSharedLy1()) - histos1d[m_name+"_sharingHits"]->Fill(5.,weight); - } - - - //TODO improve this - if (track -> is345Seed()) - histos1d[m_name+"_strategy"]->Fill(0); - if (track-> is456Seed()) - histos1d[m_name+"_strategy"]->Fill(1); - if (track-> is123SeedC4()) - histos1d[m_name+"_strategy"]->Fill(2); - if (track->is123SeedC5()) - histos1d[m_name+"_strategy"]->Fill(3); - if (track->isMatchedTrack()) - histos1d[m_name+"_strategy"]->Fill(4); - if (track->isGBLTrack()) - histos1d[m_name+"_strategy"]->Fill(5); - - histos1d[m_name+"_type" ]->Fill(track->getType() ,weight); + + //TODO improve + histos1d[m_name+"_d0" ]->Fill(track->getD0() ,weight); + histos1d[m_name+"_Phi" ]->Fill(track->getPhi() ,weight); + histos1d[m_name+"_Omega" ]->Fill(track->getOmega() ,weight); + histos1d[m_name+"_TanLambda"]->Fill(track->getTanLambda() ,weight); + histos1d[m_name+"_Z0" ]->Fill(track->getZ0() ,weight); + histos1d[m_name+"_time" ]->Fill(track->getTrackTime() ,weight); + histos1d[m_name+"_chi2" ]->Fill(track->getChi2Ndf() ,weight); + histos1d[m_name+"_nShared" ]->Fill(track->getNShared() ,weight); + + //All Tracks + histos1d[m_name+"_sharingHits"]->Fill(0.,weight); + if (track->getNShared() == 0) + histos1d[m_name+"_sharingHits"]->Fill(1.,weight); + else { + //track has shared hits + if (track->getSharedLy0()) + histos1d[m_name+"_sharingHits"]->Fill(2.,weight); + if (track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(3.,weight); + if (track->getSharedLy0() && track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(4.,weight); + if (!track->getSharedLy0() && !track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(5.,weight); + } + + + //TODO improve this + if (track -> is345Seed()) + histos1d[m_name+"_strategy"]->Fill(0); + if (track-> is456Seed()) + histos1d[m_name+"_strategy"]->Fill(1); + if (track-> is123SeedC4()) + histos1d[m_name+"_strategy"]->Fill(2); + if (track->is123SeedC5()) + histos1d[m_name+"_strategy"]->Fill(3); + if (track->isMatchedTrack()) + histos1d[m_name+"_strategy"]->Fill(4); + if (track->isGBLTrack()) + histos1d[m_name+"_strategy"]->Fill(5); + + histos1d[m_name+"_type" ]->Fill(track->getType() ,weight); } void TrackHistos::FillTrackComparisonHistograms(Track* track_x, Track* track_y, float weight) { - - if (doTrkCompPlots) { - histos2d[m_name+"_d0_vs_d0" ]->Fill(track_x->getD0(),track_y->getD0(),weight); - histos2d[m_name+"_Phi_vs_Phi" ]->Fill(track_x->getPhi(),track_y->getPhi(),weight); - histos2d[m_name+"_Omega_vs_Omega" ]->Fill(track_x->getOmega(),track_y->getOmega(),weight); - histos2d[m_name+"_TanLambda_vs_TanLambda"]->Fill(track_x->getTanLambda(),track_y->getTanLambda(),weight); - histos2d[m_name+"_Z0_vs_Z0" ]->Fill(track_x->getZ0(),track_y->getZ0(),weight); - histos2d[m_name+"_time_vs_time" ]->Fill(track_x->getTrackTime(),track_y->getTrackTime(),weight); - histos2d[m_name+"_chi2_vs_chi2" ]->Fill(track_x->getChi2Ndf(), - track_y->getChi2Ndf(), - weight); - } + + if (doTrkCompPlots) { + histos2d[m_name+"_d0_vs_d0" ]->Fill(track_x->getD0(),track_y->getD0(),weight); + histos2d[m_name+"_Phi_vs_Phi" ]->Fill(track_x->getPhi(),track_y->getPhi(),weight); + histos2d[m_name+"_Omega_vs_Omega" ]->Fill(track_x->getOmega(),track_y->getOmega(),weight); + histos2d[m_name+"_TanLambda_vs_TanLambda"]->Fill(track_x->getTanLambda(),track_y->getTanLambda(),weight); + histos2d[m_name+"_Z0_vs_Z0" ]->Fill(track_x->getZ0(),track_y->getZ0(),weight); + histos2d[m_name+"_time_vs_time" ]->Fill(track_x->getTrackTime(),track_y->getTrackTime(),weight); + histos2d[m_name+"_chi2_vs_chi2" ]->Fill(track_x->getChi2Ndf(), + track_y->getChi2Ndf(), + weight); + } } diff --git a/event/include/EventHeader.h b/event/include/EventHeader.h index 8fa3194ee..5e97f4d71 100644 --- a/event/include/EventHeader.h +++ b/event/include/EventHeader.h @@ -19,11 +19,6 @@ //----------// #include -//----------// -// event // -//----------// -#include "TriggerData.h" - class EventHeader : public TObject { public: @@ -268,21 +263,6 @@ class EventHeader : public TObject { */ double getRfTime(const int channel) const { return rf_times_[channel]; }; - /** - * Set the Trigger Data. - * - * @param trigData The parsed trigger data - * - */ - void setTriggerData(TriggerData* trigData) { tdata = trigData; }; - - /** - * Get the RF time. - * - * @return The parsed trigger data - */ - TriggerData* getTriggerData() { return tdata; }; - void Print(); private: @@ -359,9 +339,6 @@ class EventHeader : public TObject { /** The RF time */ double rf_times_[2]; - /** The parsed trigger data */ - TriggerData* tdata{nullptr}; - ClassDef(EventHeader, 1); }; // EventHeader diff --git a/processors/src/EventProcessor.cxx b/processors/src/EventProcessor.cxx index 0585f7b70..de08c75db 100644 --- a/processors/src/EventProcessor.cxx +++ b/processors/src/EventProcessor.cxx @@ -74,7 +74,6 @@ bool EventProcessor::process(IEvent* ievent) { EVENT::LCGenericObject* ts_datum = static_cast(ts_data->getElementAt(0)); - header.setTriggerData(new TriggerData(vtp_datum, ts_datum)); parseVTPData(vtp_datum); parseTSData(ts_datum); //header.setSingle0Trigger(static_cast(tdata->isSingle0Trigger())); From 26a5e14ea1afc0ebec8885d7560744cd988c5a18 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Wed, 9 Oct 2019 14:38:42 -0700 Subject: [PATCH 136/314] Clean up and renaming some stuff --- event/include/Collections.h | 3 +++ processors/config/clustersOnTracks.py | 22 ++++++++++++------- ...ocessor.h => ClusterOnTrackAnaProcessor.h} | 12 +++++----- ...sor.cxx => ClusterOnTrackAnaProcessor.cxx} | 16 +++++++------- processors/src/TrackingProcessor.cxx | 2 +- 5 files changed, 32 insertions(+), 23 deletions(-) rename processors/include/{ClusterOnTrackProcessor.h => ClusterOnTrackAnaProcessor.h} (75%) rename processors/src/{ClusterOnTrackProcessor.cxx => ClusterOnTrackAnaProcessor.cxx} (73%) diff --git a/event/include/Collections.h b/event/include/Collections.h index 11ea7ff27..a1e8364aa 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -16,6 +16,9 @@ namespace Collections { /** Name of the Raw tracker hits collection. */ constexpr const char* RAW_SVT_HITS{"SVTRawTrackerHits"}; + /** Name of the Raw tracker hits collection. */ + constexpr const char* RAW_SVT_HITS_ON_TRACK{"SVTRawHitsOnTrack"}; + /** Name of the Raw tracker fit relations collection. */ constexpr const char* RAW_SVT_HIT_FITS{"SVTFittedRawTrackerHits"}; diff --git a/processors/config/clustersOnTracks.py b/processors/config/clustersOnTracks.py index d6da50e26..088fe2ae0 100644 --- a/processors/config/clustersOnTracks.py +++ b/processors/config/clustersOnTracks.py @@ -1,5 +1,13 @@ import HpstrConf -import sys +import sys,os + +# Use the input file to set the output file name +infilename = sys.argv[1].strip() +outfilename = sys.argv[2].strip() + +print 'LCIO file: %s' % infilename +print 'Root file: %s' % outfilename + p = HpstrConf.Process() # Library containing processors @@ -7,17 +15,15 @@ #Processors -clusters = HpstrConf.Processor('clusters','ClusterOnTrackProcessor') +clusters = HpstrConf.Processor('clusters','ClusterOnTrackAnaProcessor') +clusters.parameters["BaselineFits"] = "/nfs/hps3/svtTests/jlabSystem/baselines/fits/" +clusters.parameters["BaselineRun"] = "010705" p.sequence = [clusters] -p.input_files = [ - "/nfs/slac/g/hps2/pbutti/hps_data2/hps_010487/recon/hps_10487.02292_recon_3fbfd00b3.root" -] +p.input_files = [infilename] -p.output_files = [ - "hps_10487.02292_hist_3fbfd00b3.root" -] +p.output_files = [outfilename] #p.max_events = 1000 p.printProcess() diff --git a/processors/include/ClusterOnTrackProcessor.h b/processors/include/ClusterOnTrackAnaProcessor.h similarity index 75% rename from processors/include/ClusterOnTrackProcessor.h rename to processors/include/ClusterOnTrackAnaProcessor.h index 502acd602..6da5066af 100644 --- a/processors/include/ClusterOnTrackProcessor.h +++ b/processors/include/ClusterOnTrackAnaProcessor.h @@ -1,5 +1,5 @@ -#ifndef __CLUSTERONTRACK_PROCESSOR_H__ -#define __CLUSTERONTRACK_PROCESSOR_H__ +#ifndef __CLUSTERONTRACK_ANAPROCESSOR_H__ +#define __CLUSTERONTRACK_ANAPROCESSOR_H__ //HPSTR #include "HpsEvent.h" @@ -16,13 +16,13 @@ class TTree; -class ClusterOnTrackProcessor : public Processor { +class ClusterOnTrackAnaProcessor : public Processor { public: - ClusterOnTrackProcessor(const std::string& name, Process& process); + ClusterOnTrackAnaProcessor(const std::string& name, Process& process); - ~ClusterOnTrackProcessor(); + ~ClusterOnTrackAnaProcessor(); virtual bool process(IEvent* ievent); @@ -40,7 +40,7 @@ class ClusterOnTrackProcessor : public Processor { private: - ClusterHistos* clusterHistos; + ClusterHistos* clusterHistos{nullptr}; std::string baselineFits_{""}; std::string baselineRun_{""}; diff --git a/processors/src/ClusterOnTrackProcessor.cxx b/processors/src/ClusterOnTrackAnaProcessor.cxx similarity index 73% rename from processors/src/ClusterOnTrackProcessor.cxx rename to processors/src/ClusterOnTrackAnaProcessor.cxx index 588cc2c53..fcadd40af 100644 --- a/processors/src/ClusterOnTrackProcessor.cxx +++ b/processors/src/ClusterOnTrackAnaProcessor.cxx @@ -1,12 +1,12 @@ -#include "ClusterOnTrackProcessor.h" +#include "ClusterOnTrackAnaProcessor.h" #include "TBranch.h" -ClusterOnTrackProcessor::ClusterOnTrackProcessor(const std::string& name, Process& process) : Processor(name,process){} +ClusterOnTrackAnaProcessor::ClusterOnTrackAnaProcessor(const std::string& name, Process& process) : Processor(name,process){} //TODO CHECK THIS DESTRUCTOR -ClusterOnTrackProcessor::~ClusterOnTrackProcessor(){} +ClusterOnTrackAnaProcessor::~ClusterOnTrackAnaProcessor(){} -void ClusterOnTrackProcessor::configure(const ParameterSet& parameters) { +void ClusterOnTrackAnaProcessor::configure(const ParameterSet& parameters) { baselineFits_ = parameters.getString("BaselineFits"); baselineRun_ = parameters.getString("BaselineRun"); @@ -14,7 +14,7 @@ void ClusterOnTrackProcessor::configure(const ParameterSet& parameters) { } -void ClusterOnTrackProcessor::initialize(TTree* tree) { +void ClusterOnTrackAnaProcessor::initialize(TTree* tree) { clusterHistos = new ClusterHistos("hitOnTrack_2D"); if (!baselineFits_.empty() && !baselineRun_.empty()) { @@ -32,7 +32,7 @@ void ClusterOnTrackProcessor::initialize(TTree* tree) { } -bool ClusterOnTrackProcessor::process(IEvent* ievent) { +bool ClusterOnTrackAnaProcessor::process(IEvent* ievent) { for (int itrack = 0; itracksize();itrack++) { @@ -51,7 +51,7 @@ bool ClusterOnTrackProcessor::process(IEvent* ievent) { return true; } -void ClusterOnTrackProcessor::finalize() { +void ClusterOnTrackAnaProcessor::finalize() { clusterHistos->saveHistos(outF_,""); //outF_->Close(); @@ -59,4 +59,4 @@ void ClusterOnTrackProcessor::finalize() { clusterHistos = nullptr; } -DECLARE_PROCESSOR(ClusterOnTrackProcessor); +DECLARE_PROCESSOR(ClusterOnTrackAnaProcessor); diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx index c7b5b9683..6ed57fe96 100644 --- a/processors/src/TrackingProcessor.cxx +++ b/processors/src/TrackingProcessor.cxx @@ -12,7 +12,7 @@ TrackingProcessor::~TrackingProcessor() { void TrackingProcessor::initialize(TTree* tree) { tree->Branch(Collections::GBL_TRACKS, &tracks_); tree->Branch(Collections::TRACKER_HITS, &hits_); - tree->Branch(Collections::RAW_SVT_HITS, &rawhits_); + tree->Branch(Collections::RAW_SVT_HITS_ON_TRACK, &rawhits_); } From 50bad99f6143c90dc53fe2651fb47639bf06641c Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Wed, 9 Oct 2019 14:48:30 -0700 Subject: [PATCH 137/314] Remove boost dep --- processing/include/TupleBuilder.h | 91 ------------------------------- processing/src/TupleBuilder.cxx | 36 ------------ 2 files changed, 127 deletions(-) delete mode 100644 processing/include/TupleBuilder.h delete mode 100644 processing/src/TupleBuilder.cxx diff --git a/processing/include/TupleBuilder.h b/processing/include/TupleBuilder.h deleted file mode 100644 index 4de039169..000000000 --- a/processing/include/TupleBuilder.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * @file TupleBuilder.h - * @brief Builder class to build ROOT ntuples. - * @author Omar Moreno, SLAC National Accelerator Laboratory - */ - -#ifndef __TUPLE_BUILDER_H__ -#define __TUPLE_BUILDER_H__ - -#include - -//----------// -// ROOT // -//----------// -#include "TTree.h" - -//-----------// -// boost // -//-----------// -#include "boost/assign/list_of.hpp" -#include "boost/variant.hpp" -#include "boost/unordered_map.hpp" - -typedef boost::variant< short, int, float, double, long > v; - -// Forward declerations -class TTree; - -class TupleBuilder { - - public: - - enum Type { - Short, - Int, - Float, - Double, - Long, - Bool - }; - - /** Constructor */ - TupleBuilder(TTree* tree); - - /** - * Add a leaf to the root tree. - * - * @param name The leaf name - * @param type The leaf type - */ - template - TTree* add(std::string name, Type type) { - variables_[name] = T(-9999); - tree_->Branch(name.c_str(), &boost::get(variables_[name]), - (name + "/" + type_string_[type]).c_str()); - return tree_; - } - - /** - * Access a leaf in the tree. - * - * @param name The leaf name. - */ - template - void set(std::string name, T value) { - variables_[name] = value; - } - - - private: - - /** ROOT TTree used to build the tuple. */ - TTree* tree_{nullptr}; - - /** Container for variables. */ - std::map variables_; - - /** Map from Type to string representation used by ROOT. */ - boost::unordered_map type_string_ = - { - {Type::Short, "S"}, - {Type::Int, "I"}, - {Type::Float, "F"}, - {Type::Double, "D"}, - {Type::Long, "L"}, - {Type::Bool, "O"} - }; - -}; // TupleBuilder - -#endif // __TUPLE_BUILDER_H__ diff --git a/processing/src/TupleBuilder.cxx b/processing/src/TupleBuilder.cxx deleted file mode 100644 index 998e6049d..000000000 --- a/processing/src/TupleBuilder.cxx +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file TupleBuilder.h - * @brief Builder class to build ROOT ntuples. - * @author Omar Moreno, SLAC National Accelerator Laboratory - */ - -#include "TupleBuilder.h" - -//----------// -// ROOT // -//----------// -#include "TTree.h" - -TupleBuilder::TupleBuilder(TTree* tree) : - tree_(tree) { -} - -/* -TTree* TupleBuilder::add(std::string name, Type type) { - - switch(type) { - case Short: variables_[name] = short(-9999); break; - case Int: variables_[name] = int(-9999); break; - case Float: variables_[name] = float(-9999); break; - case Double: variables_[name] = double(-9999); break; - case Long: variables_[name] = long(-9999); break; - case Bool: variables_[name] = bool(0); break; - } - - std::cout << "Old: " << variables_[name] << std::endl; - std::cout << "Old A: " << &variables_[name] << std::endl; - tree_->Branch(name.c_str(), &variables_[name], - (name + "/" + type_string_[type]).c_str()); - - return tree_; -}*/ From 6dd71521acb8fc5676d1775f1755f6fb5cf6a29f Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 10 Oct 2019 10:13:05 -0700 Subject: [PATCH 138/314] Refit tracks update: vertex classes and refit track processor. Plotting. Also changed how tres are initialized in processors:fixes running on multiple input files => no crash --- analysis/include/TrackHistos.h | 9 +- analysis/src/TrackHistos.cxx | 175 ++++++++++++++----- event/include/Collections.h | 6 +- event/include/Event.h | 5 +- event/include/Vertex.h | 14 +- event/src/Event.cxx | 2 +- event/src/Vertex.cxx | 54 ++++-- processing/include/Processor.h | 3 +- processing/src/Process.cxx | 5 +- processors/include/RefittedTracksProcessor.h | 6 + processors/src/RefittedTracksProcessor.cxx | 52 +++++- processors/src/utilities.cxx | 19 +- 12 files changed, 271 insertions(+), 79 deletions(-) diff --git a/analysis/include/TrackHistos.h b/analysis/include/TrackHistos.h index 6e64c41a8..0b2856f3f 100644 --- a/analysis/include/TrackHistos.h +++ b/analysis/include/TrackHistos.h @@ -3,6 +3,7 @@ #include "HistoManager.h" #include "Track.h" +#include "Vertex.h" #include #include @@ -22,7 +23,9 @@ class TrackHistos : public HistoManager { void BuildAxes(); - void Fill1DHistograms(Track* track, float weight = 1.); + void Fill1DHistograms(Track* track = nullptr, Vertex* vtx = nullptr, float weight = 1.); + + void Fill1DHisto(const std::string& histoName, float value, float weight=1.); //track_x goes for x axis, and y for y axis void FillTrackComparisonHistograms(Track* track_x, Track* track_y, float weight = 1.); @@ -31,6 +34,10 @@ class TrackHistos : public HistoManager { private: std::vector tPs{"d0","Phi","Omega","TanLambda","Z0","time","chi2"}; std::map > axes; + + // Vertices + std::vector vPs{"vtx_chi2", "vtx_X", "vtx_Y", "vtx_Z", "vtx_sigma_X","vtx_sigma_Y","vtx_sigma_Z","vtx_InvM","vtx_InvMErr"}; + bool doTrkCompPlots{false}; }; diff --git a/analysis/src/TrackHistos.cxx b/analysis/src/TrackHistos.cxx index 25b4c293f..96f1afa89 100644 --- a/analysis/src/TrackHistos.cxx +++ b/analysis/src/TrackHistos.cxx @@ -6,6 +6,9 @@ void TrackHistos::Define1DHistos() { //TODO improve naming std::string h_name = ""; + histos1d[m_name+"_n_tracks"] = plot1D(m_name+"_n_tracks", + "n_tracks",10,0,10); + for (unsigned int itp = 0; itpFill(value,weight); + else + std::cout<<"ERROR::Fill1DHisto Histogram not found! "<Fill(track->getD0() ,weight); - histos1d[m_name+"_Phi" ]->Fill(track->getPhi() ,weight); - histos1d[m_name+"_Omega" ]->Fill(track->getOmega() ,weight); - histos1d[m_name+"_TanLambda"]->Fill(track->getTanLambda() ,weight); - histos1d[m_name+"_Z0" ]->Fill(track->getZ0() ,weight); - histos1d[m_name+"_time" ]->Fill(track->getTrackTime() ,weight); - histos1d[m_name+"_chi2" ]->Fill(track->getChi2Ndf() ,weight); - histos1d[m_name+"_nShared" ]->Fill(track->getNShared() ,weight); - - //All Tracks - histos1d[m_name+"_sharingHits"]->Fill(0.,weight); - if (track->getNShared() == 0) - histos1d[m_name+"_sharingHits"]->Fill(1.,weight); - else { - //track has shared hits - if (track->getSharedLy0()) - histos1d[m_name+"_sharingHits"]->Fill(2.,weight); - if (track->getSharedLy1()) - histos1d[m_name+"_sharingHits"]->Fill(3.,weight); - if (track->getSharedLy0() && track->getSharedLy1()) - histos1d[m_name+"_sharingHits"]->Fill(4.,weight); - if (!track->getSharedLy0() && !track->getSharedLy1()) - histos1d[m_name+"_sharingHits"]->Fill(5.,weight); - } + if (track) { + + histos1d[m_name+"_d0" ]->Fill(track->getD0() ,weight); + histos1d[m_name+"_Phi" ]->Fill(track->getPhi() ,weight); + histos1d[m_name+"_Omega" ]->Fill(track->getOmega() ,weight); + histos1d[m_name+"_TanLambda"]->Fill(track->getTanLambda() ,weight); + histos1d[m_name+"_Z0" ]->Fill(track->getZ0() ,weight); + histos1d[m_name+"_time" ]->Fill(track->getTrackTime() ,weight); + histos1d[m_name+"_chi2" ]->Fill(track->getChi2Ndf() ,weight); + histos1d[m_name+"_nShared" ]->Fill(track->getNShared() ,weight); + + //All Tracks + histos1d[m_name+"_sharingHits"]->Fill(0.,weight); + if (track->getNShared() == 0) + histos1d[m_name+"_sharingHits"]->Fill(1.,weight); + else { + //track has shared hits + if (track->getSharedLy0()) + histos1d[m_name+"_sharingHits"]->Fill(2.,weight); + if (track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(3.,weight); + if (track->getSharedLy0() && track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(4.,weight); + if (!track->getSharedLy0() && !track->getSharedLy1()) + histos1d[m_name+"_sharingHits"]->Fill(5.,weight); + } + + + //TODO improve this + if (track -> is345Seed()) + histos1d[m_name+"_strategy"]->Fill(0); + if (track-> is456Seed()) + histos1d[m_name+"_strategy"]->Fill(1); + if (track-> is123SeedC4()) + histos1d[m_name+"_strategy"]->Fill(2); + if (track->is123SeedC5()) + histos1d[m_name+"_strategy"]->Fill(3); + if (track->isMatchedTrack()) + histos1d[m_name+"_strategy"]->Fill(4); + if (track->isGBLTrack()) + histos1d[m_name+"_strategy"]->Fill(5); + + histos1d[m_name+"_type" ]->Fill(track->getType() ,weight); + + } + //Vertices //TODO improve this - if (track -> is345Seed()) - histos1d[m_name+"_strategy"]->Fill(0); - if (track-> is456Seed()) - histos1d[m_name+"_strategy"]->Fill(1); - if (track-> is123SeedC4()) - histos1d[m_name+"_strategy"]->Fill(2); - if (track->is123SeedC5()) - histos1d[m_name+"_strategy"]->Fill(3); - if (track->isMatchedTrack()) - histos1d[m_name+"_strategy"]->Fill(4); - if (track->isGBLTrack()) - histos1d[m_name+"_strategy"]->Fill(5); - - histos1d[m_name+"_type" ]->Fill(track->getType() ,weight); + if (vtx) { + + histos1d[m_name+"_vtx_chi2"]->Fill(vtx->getChi2(),weight); + histos1d[m_name+"_vtx_X"]->Fill(vtx->getX(),weight); + histos1d[m_name+"_vtx_Y"]->Fill(vtx->getY(),weight); + histos1d[m_name+"_vtx_Z"]->Fill(vtx->getZ(),weight); + // 0 xx 1 xy 2 xz 3 yy 4 yz 5 zz + histos1d[m_name+"_vtx_sigma_X"]->Fill(sqrt(vtx->getCovariance()[0]),weight); + histos1d[m_name+"_vtx_sigma_Y"]->Fill(sqrt(vtx->getCovariance()[3]),weight); + histos1d[m_name+"_vtx_sigma_Z"]->Fill(sqrt(vtx->getCovariance()[5]),weight); + histos1d[m_name+"_vtx_InvM"]->Fill(vtx->getInvMass(),weight); + histos1d[m_name+"_vtx_InvMErr"]->Fill(vtx->getInvMassErr(),weight); + } + } diff --git a/event/include/Collections.h b/event/include/Collections.h index 5dfdf6a93..7b23089ef 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -72,7 +72,7 @@ namespace Collections { constexpr const char* TC_V0CANDIDATES{"TargetConstrainedV0Candidates"}; /** Name of the UC V0Candidates collection. */ - constexpr const char* UC_V0CANDIDATES{"UnConstrainedV0Candidates"}; + constexpr const char* UC_V0CANDIDATES{"UnconstrainedV0Candidates"}; /** Name of the V0Vertices collection. */ constexpr const char* V0VERTICES{"V0Vertices"}; @@ -81,10 +81,10 @@ namespace Collections { constexpr const char* BSC_V0VERTICES{"BeamspotConstrainedV0Vertices"}; /** Name of the TC V0Candidates collection. */ - constexpr const char* TC_V0Vertices{"TargetConstrainedV0Vertices"}; + constexpr const char* TC_V0VERTICES{"TargetConstrainedV0Vertices"}; /** Name of the UC V0Candidates collection. */ - constexpr const char* UC_V0VERTICES{"UnConstrainedV0Vertices"}; + constexpr const char* UC_V0VERTICES{"UnconstrainedV0Vertices"}; } diff --git a/event/include/Event.h b/event/include/Event.h index 08030880f..7f43932a6 100644 --- a/event/include/Event.h +++ b/event/include/Event.h @@ -85,7 +85,10 @@ class Event : public IEvent { /** @return Get a mutable copy of the EventHeader. */ EventHeader& getEventHeaderMutable() const { return *event_header_; } - + + //TODO document + void setTree(TTree* tree) {tree_ = tree;}; + /** @return The ROOT tree containing the event. */ TTree* getTree() { return tree_; } diff --git a/event/include/Vertex.h b/event/include/Vertex.h index 82664c773..e1730bb86 100644 --- a/event/include/Vertex.h +++ b/event/include/Vertex.h @@ -65,9 +65,11 @@ class Vertex : public TObject { /** Vertex parameters depend on LCIO files. * The available parameters are invMass, p1X, p2Y, p2X, p1Z, p2Z, p1Y, invMassError + * For unconstrained: + * V0PzErr, invMass, V0Pz, vXErr, V0Py, V0Px, V0PErr, V0TargProjY, vZErr, V0TargProjXErr, vYErr, V0TargProjYErr, invMassError, p1X, p2Y, p2X, V0P, p1Z, p1Y, p2Z, V0TargProjX, layerCode, V0PxErr, V0PyErr, */ - void setVtxParameters(float* parameters); + void setVtxParameters(const std::vector& parameters); void setType (const std::string& type) {type_ = type;}; std::string getType() const {return type_;}; @@ -77,16 +79,15 @@ class Vertex : public TObject { int nTracks() const; /** Returns the covariance matrix as a simple vector of values */ - const std::vector& covariance () const {return covariance_;}; + const std::vector& getCovariance () const {return covariance_;}; /** Sets the covariance matrix as a simple vector of values * Covariance matrix of the position (stored as lower triangle matrix, i.e. * cov(xx),cov(y,x),cov(y,y) ). */ - void setCovariance( const std::vector* vec); + void setCovariance( const std::vector& vec); - void setNdf (const double ndf) {ndf_ = ndf;}; double getNdf () const {return ndf_;}; @@ -140,8 +141,9 @@ class Vertex : public TObject { float probability_{-999}; int id_; std::string type_{""}; - TRefArray* tracks_; - + TRefArray* tracks_{nullptr}; + std::vector parameters_; + ClassDef(Vertex,1); }; // Vertex diff --git a/event/src/Event.cxx b/event/src/Event.cxx index fdab5acf1..b766cc8d1 100644 --- a/event/src/Event.cxx +++ b/event/src/Event.cxx @@ -10,7 +10,7 @@ Event::Event() { // Create the tree - tree_ = new TTree("HPS_Event", "HPS event tree"); + //tree_ = new TTree("HPS_Event", "HPS event tree"); // Instantiate the event header event_header_ = new EventHeader(); diff --git a/event/src/Vertex.cxx b/event/src/Vertex.cxx index d7e100e46..bdce65638 100644 --- a/event/src/Vertex.cxx +++ b/event/src/Vertex.cxx @@ -5,6 +5,7 @@ */ #include "Vertex.h" +#include ClassImp(Vertex) @@ -14,16 +15,15 @@ Vertex::Vertex() Vertex::~Vertex() { Clear(); - delete tracks_; } void Vertex::Clear(Option_t *option) { - TObject::Clear(); + //TObject::Clear(); if (tracks_) tracks_->Delete(); - pos_.Clear(); - p1_.Clear(); - p2_.Clear(); + //pos_.Clear(); + //p1_.Clear(); + //p2_.Clear(); ntracks_ = 0; x_ = -999.; y_ = -999.; @@ -44,8 +44,8 @@ int Vertex::nTracks() const { return -1; } -void Vertex::setCovariance( const std::vector* vec){ - covariance_ = *vec; +void Vertex::setCovariance( const std::vector& vec){ + covariance_ = vec; } void Vertex::setPos(const float* pos, bool rotate) { @@ -56,8 +56,42 @@ void Vertex::setPos(const float* pos, bool rotate) { x_ = pos[0]*cos(svtAngle) - pos[0]*sin(svtAngle); } else { - x_ = pos[1]; - y_ = pos[2]; - z_ = pos[0]; + // The vertex object should already by in HPS coordinates! (if not in the SVT already) + x_ = pos[0]; + y_ = pos[1]; + z_ = pos[2]; } + + pos_.SetX(x_); + pos_.SetY(y_); + pos_.SetZ(z_); + + +} + +void Vertex::setVtxParameters(const std::vector& parameters) { + parameters_ = parameters; + + //2016 invM,p1X, p2Y, p2X, p1Z, p2Z, p1Y,invMerr + if (parameters_.size() == 8 ) { + invM_ = parameters_[0]; + p1x_ = parameters_[1]; + p2y_ = parameters_[2]; + p2x_ = parameters_[3]; + p1z_ = parameters_[4]; + p2z_ = parameters_[5]; + p1y_ = parameters_[6]; + invMerr_ = parameters_[7]; + + //Build the TVector3 + p1_.SetX(p1x_); + p1_.SetY(p1y_); + p1_.SetZ(p1z_); + + //Build the TVector3 + //Build the TVector3 + p2_.SetX(p2x_); + p2_.SetY(p2y_); + p2_.SetZ(p2z_); + } } diff --git a/processing/include/Processor.h b/processing/include/Processor.h index 49655f153..cfc5af244 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -91,11 +91,12 @@ class Processor { /** Handle to the Process. */ Process& process_; - + private: /** The name of the Processor. */ std::string name_; + }; diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 6abd3ca22..ddd7f5ad1 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -94,8 +94,9 @@ void Process::run() { file = new EventFile(ifile, output_files_[cfile]); file->setupEvent(&event); } - - TTree* tree = event.getTree(); + + TTree* tree = new TTree("HPS_Event","HPS event tree"); + event.setTree(tree); // first, notify everyone that we are starting for (auto module : sequence_) { module->initialize(tree); diff --git a/processors/include/RefittedTracksProcessor.h b/processors/include/RefittedTracksProcessor.h index f6ee7ead2..2792c9113 100644 --- a/processors/include/RefittedTracksProcessor.h +++ b/processors/include/RefittedTracksProcessor.h @@ -35,6 +35,7 @@ #include "Collections.h" #include "Processor.h" #include "Track.h" +#include "Vertex.h" #include "Event.h" #include "TrackHistos.h" #include "TrackerHit.h" @@ -90,6 +91,11 @@ class RefittedTracksProcessor : public Processor { /** Container to hold the raw hits */ std::vector raw_hits_{}; + + /** Container to hold vertex objects */ + std::vector vertices_{}; + std::vector vertices_refit_{}; + bool _debug{false}; diff --git a/processors/src/RefittedTracksProcessor.cxx b/processors/src/RefittedTracksProcessor.cxx index 908510d69..a3d5652b8 100644 --- a/processors/src/RefittedTracksProcessor.cxx +++ b/processors/src/RefittedTracksProcessor.cxx @@ -10,8 +10,6 @@ RefittedTracksProcessor::RefittedTracksProcessor(const std::string& name, Proces _RefitTrkHistos = new TrackHistos("refit"); _RefitTrkHistos_z0cut = new TrackHistos("refit_z0"); _RefitTrkHistos_chi2cut = new TrackHistos("refit_chi2"); - - } RefittedTracksProcessor::~RefittedTracksProcessor() { @@ -19,7 +17,9 @@ RefittedTracksProcessor::~RefittedTracksProcessor() { void RefittedTracksProcessor::initialize(TTree* tree) { - //tree->Branch("GBLRefittedTracks", &refit_tracks_); + tree->Branch("GBLRefittedTracks", &tracks_); + tree->Branch("V0Vertices", &vertices_); + tree->Branch("V0Vertices_refit", &vertices_refit_); //Original hists @@ -48,6 +48,8 @@ bool RefittedTracksProcessor::process(IEvent* ievent) { tracks_.clear(); refit_tracks_.clear(); + vertices_.clear(); + vertices_refit_.clear(); Event* event = static_cast (ievent); //Get all the tracks @@ -59,18 +61,56 @@ bool RefittedTracksProcessor::process(IEvent* ievent) { //Get all the rawHits fits EVENT::LCCollection* raw_svt_hit_fits = event->getLCCollection(Collections::RAW_SVT_HIT_FITS); - //Initialize map of shared hits + //Grab the vertices and the vtx candidates + EVENT::LCCollection* u_vtx_candidates = nullptr; + EVENT::LCCollection* u_vtxs = nullptr; + if (utils::hasCollection(event->getLCEvent(),Collections::UC_V0CANDIDATES)) { + //Get the vertex candidates + u_vtx_candidates = event->getLCCollection(Collections::UC_V0CANDIDATES); + //Get the vertices + u_vtxs = event->getLCCollection(Collections::UC_V0VERTICES); + + + for (int ivtx = 0 ; ivtx < u_vtxs->getNumberOfElements(); ++ivtx) { + Vertex* vtx = utils::buildVertex(static_cast(u_vtxs->getElementAt(ivtx))); + vertices_.push_back(vtx); + _OriginalTrkHistos->Fill1DHistograms(nullptr,vtx); + } + _OriginalTrkHistos->Fill1DHisto("n_vertices",u_vtxs->getNumberOfElements()); + } + + //Grab the vertices and the vtx candidates + EVENT::LCCollection* u_vtx_candidates_r = nullptr; + EVENT::LCCollection* u_vtxs_r = nullptr; + if (utils::hasCollection(event->getLCEvent(),"UnconstrainedV0Candidates_refit")) { + //Get the vertex candidates + u_vtx_candidates_r = event->getLCCollection("UnconstrainedV0Candidates_refit"); + //Get the vertices + u_vtxs_r = event->getLCCollection("UnconstrainedV0Vertices_refit"); + + for (int ivtx = 0 ; ivtx < u_vtxs_r->getNumberOfElements(); ++ivtx) { + Vertex* vtx_r = utils::buildVertex(static_cast(u_vtxs_r->getElementAt(ivtx))); + vertices_refit_.push_back(vtx_r); + _RefitTrkHistos->Fill1DHistograms(nullptr,vtx_r); + } + _RefitTrkHistos->Fill1DHisto("n_vertices",u_vtxs_r->getNumberOfElements()); + } + + + //Initialize map of shared hits std::map > SharedHits; //TODO: can we do better? (innermost) std::map SharedHitsLy0; std::map SharedHitsLy1; - + for (int itrack = 0; itrack < tracks->getNumberOfElements();++itrack) { SharedHits[itrack] = {}; SharedHitsLy0[itrack] = false; SharedHitsLy1[itrack] = false; } + + _OriginalTrkHistos->Fill1DHisto("n_tracks",tracks->getNumberOfElements()); // Loop over all the LCIO Tracks and add them to the HPS event. for (int itrack = 0; itrack < tracks->getNumberOfElements(); ++itrack) { @@ -176,6 +216,8 @@ bool RefittedTracksProcessor::process(IEvent* ievent) { _OriginalTrkHistos->Fill1DHistograms(track); + _RefitTrkHistos->Fill1DHisto("n_tracks",refitted_tracks_list.size()); + for (int irtrk = 0; irtrk < refitted_tracks_list.size(); irtrk++) { if (irtrk != bestX2index) diff --git a/processors/src/utilities.cxx b/processors/src/utilities.cxx index b65356368..1c1125e94 100644 --- a/processors/src/utilities.cxx +++ b/processors/src/utilities.cxx @@ -31,11 +31,24 @@ Vertex* utils::buildVertex(EVENT::Vertex* lc_vertex) { if (!lc_vertex) return nullptr; + + //TODO move the static cast outside? Vertex* vertex = new Vertex(); - vertex->setChi2 (lc_vertex->getChi2()); - vertex->setProbability(lc_vertex->getProbability()); - + vertex->setChi2 (lc_vertex->getChi2()); + vertex->setProbability (lc_vertex->getProbability()); + vertex->setID (lc_vertex->id()); + vertex->setType (lc_vertex->getAlgorithmType()); + vertex->setVtxParameters((std::vector)lc_vertex->getParameters()); + + //TODO Rotate the covariance matrix! + vertex->setCovariance ((std::vector)lc_vertex->getCovMatrix()); + //std::cout<getVertexParameterNames[0]<setType (lc_vertex->getAlgorithmType()); + + vertex->setPos (lc_vertex->getPosition(),false); + + return vertex; } From 14a57ef25596cb002d67fb148a26cc0ad902abef Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 10 Oct 2019 10:14:03 -0700 Subject: [PATCH 139/314] Use of proper rotated coordinates. X is now in SVT frame --- event/src/TrackerHit.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/event/src/TrackerHit.cxx b/event/src/TrackerHit.cxx index 237c927cc..f41595671 100644 --- a/event/src/TrackerHit.cxx +++ b/event/src/TrackerHit.cxx @@ -33,9 +33,9 @@ void TrackerHit::setPosition(const double* position, bool rotate) { x_ = position[1] * cos(svtAngle) - position[0]*sin(svtAngle); } else { - x_ = position[0]; - y_ = position[1]; - z_ = position[2]; + x_ = position[1]; + y_ = position[2]; + z_ = position[0]; } } From 0cc7ea10389f34e64b722be7def13a8faa6c27b6 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Fri, 11 Oct 2019 11:46:10 -0700 Subject: [PATCH 140/314] Update to RawSvtDataProcessor --- processors/src/SvtRawDataProcessor.cxx | 5 ++--- pyplot/utilities.py | 15 ++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 29d60de4a..8640fed0c 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -15,6 +15,7 @@ SvtRawDataProcessor::~SvtRawDataProcessor() { void SvtRawDataProcessor::initialize(TTree* tree) { rawhits_ = new TClonesArray("RawSvtHit", 100000); + tree->Branch(Collections::RAW_SVT_HITS,&rawhits_); } bool SvtRawDataProcessor::process(IEvent* ievent) { @@ -46,6 +47,7 @@ bool SvtRawDataProcessor::process(IEvent* ievent) { // Loop over all of the raw SVT hits in the LCIO event and add them to the // HPS event + rawhits_->Clear(); for (int ihit = 0; ihit < raw_svt_hits->getNumberOfElements(); ++ihit) { // Get a 3D hit from the list of hits @@ -102,9 +104,6 @@ bool SvtRawDataProcessor::process(IEvent* ievent) { } - // Add the raw hit collection to the event - event->addCollection(Collections::RAW_SVT_HITS, rawhits_); - //Clean up if (hasFits) delete rawTracker_hit_fits_nav; diff --git a/pyplot/utilities.py b/pyplot/utilities.py index 9b7f0f424..3a5e9bec9 100755 --- a/pyplot/utilities.py +++ b/pyplot/utilities.py @@ -387,7 +387,7 @@ def DivideHistos(h1,h2): -def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1,noErrors=False,RebinFactor=0,runNumber="",additionalText=[],LogX=False,WriteMean=False,multiLeg=False): +def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1,noErrors=False,RebinFactor=0,runNumber="",additionalText=[],LogY=False,WriteMean=False,multiLeg=False): if not os.path.exists(outdir): @@ -395,8 +395,8 @@ def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle can = TCanvas() - if LogX: - can.SetLogx(1) + if LogY: + can.SetLogy(1) means = [] meansErr = [] @@ -411,20 +411,19 @@ def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle histos[ih].SetMarkerStyle(markers[ih]) histos[ih].SetLineColor(colors[ih]) histos[ih].GetYaxis().SetRangeUser(ymin,ymax) + histos[ih].GetXaxis().CenterTitle() + histos[ih].GetYaxis().CenterTitle() if ("pT" in name or "pt" in name): histos[ih].GetXaxis().SetRangeUser(1.,20.) #histos[ih].SetMarkerSize(0.5) if RebinFactor>0: histos[ih].Rebin(RebinFactor) - if ih==0: if noErrors: histos[ih].GetXaxis().SetTextSize(0.045) histos[ih].GetYaxis().SetTextSize(0.045) histos[ih].Draw("hist p") - - else: histos[ih].Draw() if xtitle: @@ -436,10 +435,8 @@ def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle histos[ih].Draw("same hist p") else: histos[ih].Draw("same") - - - InsertText(runNumber,additionalText,0.52) + InsertText(runNumber,additionalText,0.85,xoffset=0.7) if len(legends)>0: #print "building legend" From 9f133fe6e4a546edb9fef1754779470eda41cbf7 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 17 Oct 2019 09:32:05 -0700 Subject: [PATCH 141/314] Add event/MCParticle and compilmentary processor --- CMakeLists.txt | 3 + cmake/Modules/FindLCIO.cmake | 9 ++ event/include/Collections.h | 3 + event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 5 + event/include/MCParticle.h | 180 +++++++++++++++++++++++ event/src/MCParticle.cxx | 47 ++++++ processors/include/MCParticleProcessor.h | 90 ++++++++++++ processors/src/MCParticleProcessor.cxx | 153 +++++++++++++++++++ processors/src/SvtRawDataProcessor.cxx | 2 +- 10 files changed, 492 insertions(+), 1 deletion(-) create mode 100644 cmake/Modules/FindLCIO.cmake create mode 100644 event/include/MCParticle.h create mode 100644 event/src/MCParticle.cxx create mode 100644 processors/include/MCParticleProcessor.h create mode 100644 processors/src/MCParticleProcessor.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 05e0fa533..729a19110 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,9 @@ if(NOT CMAKE_BUILD_TYPE) endif() set(CMAKE_CXX_FLAGS_RELEASE "-O3") +# add dir with extra CMake modules +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules/) + # find the LCIO directory if (LCIO_DIR) set(LCIO_INCLUDE_DIR "${LCIO_DIR}/include") diff --git a/cmake/Modules/FindLCIO.cmake b/cmake/Modules/FindLCIO.cmake new file mode 100644 index 000000000..174f619d1 --- /dev/null +++ b/cmake/Modules/FindLCIO.cmake @@ -0,0 +1,9 @@ +find_path(LCIO_INCLUDE_DIR lcio.h ${LCIO_DIR}/include) + +find_library(LCIO_LIBRARY lcio ${LCIO_DIR}/lib) +find_library(SIO_LIBRARY sio ${LCIO_DIR}/lib) +set(LCIO_LIBRARIES ${LCIO_LIBRARY} ${SIO_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( LCIO DEFAULT_MSG LCIO_LIBRARIES LCIO_INCLUDE_DIR ) diff --git a/event/include/Collections.h b/event/include/Collections.h index a1e8364aa..cd0646714 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -43,6 +43,9 @@ namespace Collections { /** Name of the collection containing Final State Particles. */ constexpr const char* FINAL_STATE_PARTICLES{"FinalStateParticles"}; + /** Name of the collection containing MC Particles. */ + constexpr const char* MC_PARTICLES{"MCParticle"}; + /** Name of time corrected ECal hits collection. */ constexpr const char* ECAL_TIME_CORR_HITS{"TimeCorrEcalHits"}; diff --git a/event/include/EventDef.h b/event/include/EventDef.h index ab28849d1..d21b624d8 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -7,6 +7,7 @@ #include "VTPData.h" #include "TSData.h" #include "Particle.h" +#include "MCParticle.h" #include "Track.h" #include "Vertex.h" #include "TrackerHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index e3b6ce785..b4b09cd8b 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -24,6 +24,7 @@ #pragma link C++ class TSData::tsHeader+; #pragma link C++ class TSData::tsBits+; #pragma link C++ class Particle+; +#pragma link C++ class MCParticle+; #pragma link C++ class Track+; #pragma link C++ class Vertex+; #pragma link C++ class TrackerHit+; @@ -40,6 +41,10 @@ #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; diff --git a/event/include/MCParticle.h b/event/include/MCParticle.h new file mode 100644 index 000000000..3f5353876 --- /dev/null +++ b/event/include/MCParticle.h @@ -0,0 +1,180 @@ +/** + * @file MCParticle.h + * @brief Class used to encapsulate information about a mc particle. + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef _MCPARTICLE_H_ +#define _MCPARTICLE_H_ + +//----------// +// ROOT // +//----------// +#include +#include +#include +#include + + +class MCParticle : public TObject { + + public: + + /** Default Constructor. */ + MCParticle(); + + /** Destructor. */ + ~MCParticle(); + + /** Reset this MCParticle object */ + void Clear(Option_t *option=""); + + /** + * Add a reference to an Particle object. This will be used to + * add daughter particles to this particle. + * + * @param particle Daughter particle composing this particle + */ + void addDaughter(MCParticle* particle); + + /** + * Get the daughter particles composing this particle. + * + * @return An array of references to the daughter particles associated + * with this particle + */ + TRefArray* getDaughters() const { return daughters_; }; + + /** + * Set the charge of the particle. + * + * @param charge_ MCParticle charge + */ + void setCharge(const int charge) { charge_ = charge; }; + + /** + * Set the PDG ID of this particle. + * + * @param pdg The PDG ID of this particle + */ + void setPDG(const int pdg) { pdg_ = pdg; }; + + /** + * Set the energy of the particle in GeV. + * + * @param energy The energy of this particle + */ + void setEnergy(const double energy) { energy_ = energy; }; + + /** + * Set the invariant mass of the particle in GeV. + * + * @param mass The invariant mass of the particle + */ + void setMass(const double mass) { mass_ = mass; }; + + /** + * Set the invariant mass of the particle in GeV. + * + * @param mass The invariant mass of the particle + */ + void setTime(const double time) { time_ = time; }; + + /** + * Set the momentum of the particle in GeV. + * + * @param momentum An array containing the three momentum components + * of the particle. + */ + void setMomentum(const double* momentum); + + /** + * Set the vertex position of the particle. + * + * @param vtx_pos An array containing the three vertex position + * components of the particle + */ + void setVertexPosition(const float* vtx_pos); + + /** @return The particle charge. */ + int getCharge() const { return charge_; }; + + /** @return The particle ID. */ + int getPDG() const { return pdg_; }; + + /** @return The particle energy in GeV. */ + double getEnergy() const { return energy_; }; + + /** @return The invariant mass of the particle in GeV. */ + double getMass() const { return mass_; }; + + /** @return The time of the particle */ + double getTime() const { return time_; }; + + /** @return The momentum of the particle. */ + std::vector getMomentum() const; + + /** @return The vertex position of the particle. */ + std::vector getVertexPosition() const; + + /** @return The vertex position of the particle. */ + std::vector getEndPoint() const; + + ClassDef(MCParticle, 1); + + private: + + /** + * An array of references to daughter particles associated with this + * particle + */ + TRefArray* daughters_{new TRefArray{}}; + + /** The number of daughters associated with this particle */ + int n_daughters_{0}; + + /** The charge of this particle */ + int charge_{-9999}; + + /** The PDG ID of this particle */ + int pdg_{-9999}; + + /** The x component of the momentum of this particle in GeV */ + double px_{-9999}; + + /** The y component of the momentum of this particle in GeV */ + double py_{-9999}; + + /** The z component of the momentum of this particle in GeV */ + double pz_{-9999}; + + /** The x component of the vertex of this particle in mm*/ + double vtx_x_{-9999}; + + /** The y component of the vertex of this particle in mm */ + double vtx_y_{-9999}; + + /** The z component of the vertex of this particle in mm */ + double vtx_z_{-9999}; + + /** The x component of the end point of this particle in mm*/ + double ep_x_{-9999}; + + /** The y component of the end point of this particle in mm */ + double ep_y_{-9999}; + + /** The z component of the end point of this particle in mm */ + double ep_z_{-9999}; + + /** The energy of the particle in GeV */ + double energy_{-9999}; + + /** The invariant mass of the particle in GeV */ + double mass_{-9999}; + + /** The time of the particle */ + double time_{-9999}; + +}; // MCParticle + +#endif // _MCPARTICLE_H_ diff --git a/event/src/MCParticle.cxx b/event/src/MCParticle.cxx new file mode 100644 index 000000000..f8a3466ed --- /dev/null +++ b/event/src/MCParticle.cxx @@ -0,0 +1,47 @@ +/** + * @file MCParticle.cxx + * @brief Class used to encapsulate information about a particle. + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#include "MCParticle.h" + +ClassImp(MCParticle) + +MCParticle::MCParticle() + : TObject() { +} + +MCParticle::~MCParticle() { + Clear(); + delete daughters_; +} + +void MCParticle::Clear(Option_t* /* option */) { + TObject::Clear(); + daughters_->Delete(); + n_daughters_ = 0; +} + +void MCParticle::addDaughter(MCParticle* particle) { + ++n_daughters_; + daughters_->Add(static_cast(particle)); +} + +void MCParticle::setMomentum(const double* momentum) { + px_ = momentum[0]; + py_ = momentum[1]; + pz_ = momentum[2]; +} + +std::vector MCParticle::getMomentum() const { return { px_, py_, pz_ }; } + +void MCParticle::setVertexPosition(const float* vtx_pos) { + vtx_x_ = static_cast(vtx_pos[0]); + vtx_y_ = static_cast(vtx_pos[1]); + vtx_z_ = static_cast(vtx_pos[2]); +} + +std::vector MCParticle::getVertexPosition() const { + return { vtx_x_, vtx_y_, vtx_z_ }; +} diff --git a/processors/include/MCParticleProcessor.h b/processors/include/MCParticleProcessor.h new file mode 100644 index 000000000..565fcf396 --- /dev/null +++ b/processors/include/MCParticleProcessor.h @@ -0,0 +1,90 @@ +/** + * @file MCParticleProcessor.h + * @brief Processor used to translate LCIO MCParticles to DST + * MCParticle objects. + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef _MCPARTICLE_PROCESSOR_H_ +#define _MCPARTICLE_PROCESSOR_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include +#include +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +//#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" +#include "TTree.h" + +//-----------// +// hpstr // +//-----------// +#include "CalCluster.h" +#include "Collections.h" +#include "MCParticle.h" +#include "Processor.h" +#include "Track.h" +#include "Event.h" + +class MCParticleProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + MCParticleProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~MCParticleProcessor(); + + /** + * Callback for the EventProcessor to configure itself from the given set of parameters. + * @param parameters ParameterSet for configuration. + */ + virtual void configure(const ParameterSet& parameters); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(TTree* tree); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual bool process(IEvent* ievent); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Map to hold all particle collections. */ + TClonesArray* mc_particles_; + +}; // MCParticleProcessor + +#endif // _MCPARTICLE_PROCESSOR_H_ diff --git a/processors/src/MCParticleProcessor.cxx b/processors/src/MCParticleProcessor.cxx new file mode 100644 index 000000000..01ca99f66 --- /dev/null +++ b/processors/src/MCParticleProcessor.cxx @@ -0,0 +1,153 @@ +/** + * @file MCParticleProcessor.cxx + * @brief Processor used to translate LCIO ReconstructedParticles to DST + * MCParticle objects. + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#include "MCParticleProcessor.h" + +MCParticleProcessor::MCParticleProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +MCParticleProcessor::~MCParticleProcessor() { +} + +void MCParticleProcessor::configure(const ParameterSet& parameters) { + +} + +void MCParticleProcessor::initialize(TTree* tree) { + // Create a new TClonesArray collection + mc_particles_ = new TClonesArray(Collections::MC_PARTICLES, 1000000); + // Add branch to tree + tree->Branch(Collections::MC_PARTICLES,&mc_particles_); + +} + +bool MCParticleProcessor::process(IEvent* ievent) { + + Event* event = static_cast (ievent); + + // Get the collection from the event + EVENT::LCCollection* lc_particles = event->getLCCollection(Collections::MC_PARTICLES); + + mc_particles_->Clear(); + + // Loop through all of the particles in the event + for (int iparticle = 0; iparticle < lc_particles->getNumberOfElements(); ++iparticle) { + + // Get a particle from the LCEvent + IMPL::MCParticleImpl* lc_particle + = static_cast(lc_particles->getElementAt(iparticle)); + + // Make an MCParticle to build and add to TClonesArray + MCParticle* particle = static_cast(mc_particles_->ConstructedAt(iparticle)); + + // Set the charge of the HpsMCParticle + particle->setCharge(lc_particle->getCharge()); + + // Set the HpsMCParticle type + particle->setTime(lc_particle->getTime()); + + // Set the energy of the HpsMCParticle + particle->setEnergy(lc_particle->getEnergy()); + + // Set the momentum of the HpsMCParticle + particle->setMomentum(lc_particle->getMomentum()); + + // Set the mass of the HpsMCParticle + particle->setMass(lc_particle->getMass()); + + // Set the PDG of the particle + particle->setPDG(lc_particle->getPDG()); + + // Loop through all of the tracks associated with the particle + // and add references to the MCParticle object. + /*for (auto const &lc_track : lc_particle->getTracks()) { + + TClonesArray* tracks = event->getCollection(Collections::GBL_TRACKS); + + // Loop through all of the tracks in the HpsEvent and find the one + // that matches the track associated with the particle + for (int itrack = 0; itrack < tracks->GetEntriesFast(); ++itrack) { + Track* track = static_cast(tracks->At(itrack)); + + // Use the track chi^2 to find the match + // TODO: Verify that the chi^2 is unique enough to find the match + if (lc_track->getChi2() == track->getChi2()) { + + // Add a reference to the track + particle->addTrack(track); + + // If the particle is a final state particle, add a + // reference from the corresponding track to the particle + if ((collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) + || (collections.first.compare(Collections::OTHER_ELECTRONS) == 0) ) { + track->setMCParticle(particle); + track->setMomentum(particle->getMomentum()); + track->setCharge(particle->getCharge()); + } + break; + } + } + + }*/ + + // Only add vertex information if the particle is not a final state particle + //if ((collections.first.compare(Collections::FINAL_STATE_PARTICLES) == 0) || + // (collections.first.compare(Collections::OTHER_ELECTRONS) == 0)) { + // // Set the PDG ID of the particle + // particle->setPDG(lc_particle->getParticleIDUsed()->getPDG()); + // continue; + //} + + // Set the vertex position of the particle + //EVENT::Vertex* vtx = static_cast(lc_particle->getStartVertex()); + //particle->setVertexPosition(vtx->getPosition()); + + // If the particle has daughter particles, add the daughters to the + // MCParticle. + // + + // Loop through all of the daughter particles associated with the particle + /*for (auto const &daughter : lc_particle->getParticles()) { + + // Loop through all of the final state particles in the event + // and find the one that matches the daughters associated with + // the particles. + for (int iparticle = 0; + iparticle < fs_particles->GetEntriesFast(); ++iparticle) { + + MCParticle* dparticle = static_cast(fs_particles->At(iparticle)); + + // Try to find the match between a final state particle + // and ReconstructedParticle daughter. For now, use the + // momentum as the matching criterion. + // TODO: Verify that the track momentum is always unique in an event. + if ((dparticle->getMomentum()[0] == lc_particle->getMomentum()[0]) + && (dparticle->getMomentum()[1] == lc_particle->getMomentum()[1]) + && (dparticle->getMomentum()[2] == lc_particle->getMomentum()[2])) { + + particle->addDaughter(dparticle); + + if (dparticle->getTracks()->GetEntriesFast() != 0) + particle->addTrack(dparticle->getTracks()->At(0)); + + if (dparticle->getClusters()->GetEntriesFast() != 0) + particle->addCluster(dparticle->getClusters()->At(0)); + + break; + } + } + }*/ + } + + return true; +} + +void MCParticleProcessor::finalize() { +} + +DECLARE_PROCESSOR(MCParticleProcessor); diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index 8640fed0c..d28e08717 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -14,7 +14,7 @@ SvtRawDataProcessor::~SvtRawDataProcessor() { void SvtRawDataProcessor::initialize(TTree* tree) { - rawhits_ = new TClonesArray("RawSvtHit", 100000); + rawhits_ = new TClonesArray(Collections::RAW_SVT_HITS, 100000); tree->Branch(Collections::RAW_SVT_HITS,&rawhits_); } From 062c3262e4fc8ea97ac1355725ef7a628fead303 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 17 Oct 2019 09:52:57 -0700 Subject: [PATCH 142/314] Add vertex position to MCParticle --- event/include/MCParticle.h | 2 +- event/src/MCParticle.cxx | 2 +- processors/src/MCParticleProcessor.cxx | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/event/include/MCParticle.h b/event/include/MCParticle.h index 3f5353876..58a1e259e 100644 --- a/event/include/MCParticle.h +++ b/event/include/MCParticle.h @@ -94,7 +94,7 @@ class MCParticle : public TObject { * @param vtx_pos An array containing the three vertex position * components of the particle */ - void setVertexPosition(const float* vtx_pos); + void setVertexPosition(const double* vtx_pos); /** @return The particle charge. */ int getCharge() const { return charge_; }; diff --git a/event/src/MCParticle.cxx b/event/src/MCParticle.cxx index f8a3466ed..2ea144ab7 100644 --- a/event/src/MCParticle.cxx +++ b/event/src/MCParticle.cxx @@ -36,7 +36,7 @@ void MCParticle::setMomentum(const double* momentum) { std::vector MCParticle::getMomentum() const { return { px_, py_, pz_ }; } -void MCParticle::setVertexPosition(const float* vtx_pos) { +void MCParticle::setVertexPosition(const double* vtx_pos) { vtx_x_ = static_cast(vtx_pos[0]); vtx_y_ = static_cast(vtx_pos[1]); vtx_z_ = static_cast(vtx_pos[2]); diff --git a/processors/src/MCParticleProcessor.cxx b/processors/src/MCParticleProcessor.cxx index 01ca99f66..97595abd4 100644 --- a/processors/src/MCParticleProcessor.cxx +++ b/processors/src/MCParticleProcessor.cxx @@ -104,8 +104,7 @@ bool MCParticleProcessor::process(IEvent* ievent) { //} // Set the vertex position of the particle - //EVENT::Vertex* vtx = static_cast(lc_particle->getStartVertex()); - //particle->setVertexPosition(vtx->getPosition()); + particle->setVertexPosition(lc_particle->getVertex()); // If the particle has daughter particles, add the daughters to the // MCParticle. From d11a214e24ab757703f11096fe88e4b3107578d8 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 17 Oct 2019 10:05:34 -0700 Subject: [PATCH 143/314] Add endpoints to MCParticle --- event/include/MCParticle.h | 8 ++++++++ event/src/MCParticle.cxx | 16 +++++++++++++--- processors/src/MCParticleProcessor.cxx | 3 +++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/event/include/MCParticle.h b/event/include/MCParticle.h index 58a1e259e..5ff7908b9 100644 --- a/event/include/MCParticle.h +++ b/event/include/MCParticle.h @@ -95,6 +95,14 @@ class MCParticle : public TObject { * components of the particle */ void setVertexPosition(const double* vtx_pos); + + /** + * Set the end point of the particle. + * + * @param ep_pos An array containing the three endpoint + * components of the particle + */ + void setEndPoint(const double* ep_pos); /** @return The particle charge. */ int getCharge() const { return charge_; }; diff --git a/event/src/MCParticle.cxx b/event/src/MCParticle.cxx index 2ea144ab7..33780dc9d 100644 --- a/event/src/MCParticle.cxx +++ b/event/src/MCParticle.cxx @@ -37,11 +37,21 @@ void MCParticle::setMomentum(const double* momentum) { std::vector MCParticle::getMomentum() const { return { px_, py_, pz_ }; } void MCParticle::setVertexPosition(const double* vtx_pos) { - vtx_x_ = static_cast(vtx_pos[0]); - vtx_y_ = static_cast(vtx_pos[1]); - vtx_z_ = static_cast(vtx_pos[2]); + vtx_x_ = vtx_pos[0]; + vtx_y_ = vtx_pos[1]; + vtx_z_ = vtx_pos[2]; +} + +void MCParticle::setEndPoint(const double* ep_pos) { + ep_x_ = ep_pos[0]; + ep_y_ = ep_pos[1]; + ep_z_ = ep_pos[2]; } std::vector MCParticle::getVertexPosition() const { return { vtx_x_, vtx_y_, vtx_z_ }; } + +std::vector MCParticle::getEndPoint() const { + return { ep_x_, ep_y_, ep_z_ }; +} diff --git a/processors/src/MCParticleProcessor.cxx b/processors/src/MCParticleProcessor.cxx index 97595abd4..c49828567 100644 --- a/processors/src/MCParticleProcessor.cxx +++ b/processors/src/MCParticleProcessor.cxx @@ -106,6 +106,9 @@ bool MCParticleProcessor::process(IEvent* ievent) { // Set the vertex position of the particle particle->setVertexPosition(lc_particle->getVertex()); + // Set the vertex position of the particle + particle->setEndPoint(lc_particle->getEndpoint()); + // If the particle has daughter particles, add the daughters to the // MCParticle. // From 61cc09bdef8b7e31393648b9fc3a5d33ea91fce9 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Fri, 18 Oct 2019 16:42:00 -0700 Subject: [PATCH 144/314] Minor clean up --- README.md | 4 +- event/include/TrackerHit.h | 100 +++++++++--------- event/src/TrackerHit.cxx | 28 ++--- event/src/Vertex.cxx | 34 +++--- processing/src/hpstr.cxx | 32 +++--- .../include/ClusterOnTrackAnaProcessor.h | 70 ++++++------ processors/src/ClusterOnTrackAnaProcessor.cxx | 76 ++++++------- 7 files changed, 173 insertions(+), 171 deletions(-) diff --git a/README.md b/README.md index 2bb88a849..fdcd2225d 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -Heavy Photon Search Toolkit for Reconstruction +# Heavy Photon Search Toolkit for Reconstruction + +The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format. It also provides tools which can be used to analyze the ROOT format of the data. diff --git a/event/include/TrackerHit.h b/event/include/TrackerHit.h index 792332c62..b0dc19a2f 100644 --- a/event/include/TrackerHit.h +++ b/event/include/TrackerHit.h @@ -24,17 +24,17 @@ class TrackerHit : public TObject { public: /** Constructor */ - TrackerHit(); + TrackerHit(); /** Destructor */ - virtual ~TrackerHit(); + virtual ~TrackerHit(); /** Reset the Hit object. */ void Clear(Option_t *option=""); /** Get the references to the raw hits associated with this tracker hit */ TRefArray* getRawHits() const {return raw_hits_;}; - + /** * Set the hit position. * @@ -85,39 +85,39 @@ class TrackerHit : public TObject { /** @return The hit charge. */ double getCharge() const { return charge_; }; - void setRawCharge(const double rawcharge) { rawcharge_ = rawcharge; }; + void setRawCharge(const double rawcharge) { rawcharge_ = rawcharge; }; /** @return The hit charge. */ double getRawCharge() const { return rawcharge_; }; - void setVolume(const int volume ) {volume_ = volume;} ; - - //** @return the tracker hit volume from the raw hit content */ - int getVolume() { return volume_;} ; - - //** set the tracker hit layer from the raw hit content */ - void setLayer(const int layer) {layer_ = layer;}; - - //** @return the tracker hit layer from the raw hit content */ - int getLayer() const {return layer_;}; - - /** Is a hit shared between multiple tracks. */ - bool isShared() const ; - - /** Add raw hit to the raw hit reference array */ + void setVolume(const int volume ) {volume_ = volume;} ; + + //** @return the tracker hit volume from the raw hit content */ + int getVolume() { return volume_;} ; + + //** set the tracker hit layer from the raw hit content */ + void setLayer(const int layer) {layer_ = layer;}; + + //** @return the tracker hit layer from the raw hit content */ + int getLayer() const {return layer_;}; + + /** Is a hit shared between multiple tracks. */ + bool isShared() const ; + + /** Add raw hit to the raw hit reference array */ void addRawHit(TObject* rawhit) { - ++n_rawhits_; - raw_hits_->Add(rawhit); - } + ++n_rawhits_; + raw_hits_->Add(rawhit); + } - //TODO: I use this to get the shared hits. Not sure if useful. - /** LCIO id */ - void setID(const int id) {id_=id;}; + //TODO: I use this to get the shared hits. Not sure if useful. + /** LCIO id */ + void setID(const int id) {id_=id;}; - int getID() const {return id_;}; + int getID() const {return id_;}; ClassDef(TrackerHit, 1); - + private: /** Number of raw hits forming the Tracker hit */ @@ -125,10 +125,10 @@ class TrackerHit : public TObject { /** The x position of the hit. */ double x_{-999}; - + /** The x position of the hit. */ double y_{-999}; - + /** The x position of the hit. */ double z_{-999}; @@ -142,31 +142,31 @@ class TrackerHit : public TObject { /** The hit time. */ double time_{-999}; - + /** The hit charge deposit. */ double charge_{-999}; - /** The raw hits */ + /** The raw hits */ TRefArray* raw_hits_{new TRefArray{}}; - - /** Layer (Axial + Stereo). 1-6 in 2015/2016 geometry, 0-7 in 2019 geometry */ - int layer_{-999}; - - /** Volume 0-top 1-bottom) */ - int volume_{-999}; - - /** Raw charge: sum of the raw hit fit amplitudes */ - float rawcharge_{-999}; - - /** How many tracks share this hit */ - int shared_{-999}; - - /** LCIO id */ - int id_{-999}; - - /** Tracks that share this hit */ - TRefArray* tracks_{new TRefArray{}}; - + + /** Layer (Axial + Stereo). 1-6 in 2015/2016 geometry, 0-7 in 2019 geometry */ + int layer_{-999}; + + /** Volume 0-top 1-bottom) */ + int volume_{-999}; + + /** Raw charge: sum of the raw hit fit amplitudes */ + float rawcharge_{-999}; + + /** How many tracks share this hit */ + int shared_{-999}; + + /** LCIO id */ + int id_{-999}; + + /** Tracks that share this hit */ + TRefArray* tracks_{new TRefArray{}}; + }; // TrackerHit diff --git a/event/src/TrackerHit.cxx b/event/src/TrackerHit.cxx index 237c927cc..7f3031279 100644 --- a/event/src/TrackerHit.cxx +++ b/event/src/TrackerHit.cxx @@ -21,22 +21,22 @@ void TrackerHit::Clear(Option_t* /* options */) { } void TrackerHit::setPosition(const double* position, bool rotate) { - - //svt angle: it's already with minus sign. - float svtAngle = 30.5e-3; - //Rotate the the input position automatically to match with the SVT tracker system - if (rotate) + + //svt angle: it's already with minus sign. + float svtAngle = 30.5e-3; + //Rotate the the input position automatically to match with the SVT tracker system + if (rotate) { - //x_ = position[1]; - y_ = position[2]; - z_ = position[1] * sin(svtAngle) + position[0]*cos(svtAngle); - x_ = position[1] * cos(svtAngle) - position[0]*sin(svtAngle); + //x_ = position[1]; + y_ = position[2]; + z_ = position[1] * sin(svtAngle) + position[0]*cos(svtAngle); + x_ = position[1] * cos(svtAngle) - position[0]*sin(svtAngle); + } + else { + x_ = position[0]; + y_ = position[1]; + z_ = position[2]; } - else { - x_ = position[0]; - y_ = position[1]; - z_ = position[2]; - } } void TrackerHit::setCovarianceMatrix(const std::vector covariance_matrix) { diff --git a/event/src/Vertex.cxx b/event/src/Vertex.cxx index 1a67ac4bd..9926f543c 100644 --- a/event/src/Vertex.cxx +++ b/event/src/Vertex.cxx @@ -9,33 +9,33 @@ ClassImp(Vertex) Vertex::Vertex() -: TObject() { -} + : TObject() { + } Vertex::~Vertex() { - Clear(); - delete tracks_; + Clear(); + delete tracks_; } void Vertex::Clear(Option_t *option) { - TObject::Clear(); - if (tracks_) - tracks_->Delete(); - pos_.Clear(); - p1_.Clear(); - p2_.Clear(); - ntracks_ = 0; - x_ = -999.; - y_ = -999.; - z_ = -999.; + TObject::Clear(); + if (tracks_) + tracks_->Delete(); + pos_.Clear(); + p1_.Clear(); + p2_.Clear(); + ntracks_ = 0; + x_ = -999.; + y_ = -999.; + z_ = -999.; } bool Vertex::vxTracksAvailable() const { - if (tracks_) - return true; + if (tracks_) + return true; - return false; + return false; } void Vertex::setCovariance ( const std::vector* vec) { diff --git a/processing/src/hpstr.cxx b/processing/src/hpstr.cxx index 09a620a6d..9a8be7152 100644 --- a/processing/src/hpstr.cxx +++ b/processing/src/hpstr.cxx @@ -30,7 +30,7 @@ int main(int argc, char **argv) { } bool processRoot = false; - + int ptrpy = 1; for (ptrpy = 1; ptrpy < argc; ptrpy++) { std::cout << argv[ptrpy] << std::endl; @@ -45,15 +45,15 @@ int main(int argc, char **argv) { } try { - + std::cout << "---- [ hpstr ]: Loading configuration --------" << std::endl; - + ConfigurePython cfg(argv[ptrpy], argv + ptrpy + 1, argc - ptrpy); std::cout << "---- [ hpstr ]: Configuration load complete --------" << std::endl; Process* p = cfg.makeProcess(); - + std::cout << "---- [ hpstr ]: Process initialized. --------" << std::endl; // If Ctrl-c is used, immediately exit the application. @@ -66,22 +66,22 @@ int main(int argc, char **argv) { std::cout << "---- [ hpstr ]: Starting event processing --------" << std::endl; - //TODO Make this better - if (p->processRootFiles()) { - std::cout<<"---- [ hpstr ]: Running on ROOT Files --------" << std::endl; - p->runOnRoot(); - } - else { - std::cout<<"---- [ hpstr ]: Running on LCIO Files --------" << std::endl; - p->run(); - } - + //TODO Make this better + if (p->processRootFiles()) { + std::cout<<"---- [ hpstr ]: Running on ROOT Files --------" << std::endl; + p->runOnRoot(); + } + else { + std::cout<<"---- [ hpstr ]: Running on LCIO Files --------" << std::endl; + p->run(); + } + std::cout << "---- [ hpstr ]: Event processing complete --------" << std::endl; } catch (exception& e) { //std::cerr << "Error! [" << e.name() << "] : " << e.message() << std::endl; //std::cerr << " at " << e.module() << ":" << e.line() << " in " << e.function() << std::endl; - + } return EXIT_SUCCESS; @@ -90,5 +90,5 @@ int main(int argc, char **argv) { void displayUsage() { printf("Usage: hpstr [application arguments] {configuration_script.py}" - " [arguments to configuration script]\n"); + " [arguments to configuration script]\n"); } diff --git a/processors/include/ClusterOnTrackAnaProcessor.h b/processors/include/ClusterOnTrackAnaProcessor.h index 6da5066af..e13866748 100644 --- a/processors/include/ClusterOnTrackAnaProcessor.h +++ b/processors/include/ClusterOnTrackAnaProcessor.h @@ -18,41 +18,41 @@ class TTree; class ClusterOnTrackAnaProcessor : public Processor { - public: - - ClusterOnTrackAnaProcessor(const std::string& name, Process& process); - - ~ClusterOnTrackAnaProcessor(); - - virtual bool process(IEvent* ievent); - - virtual void initialize(TTree* tree); - - virtual void finalize(); - - virtual void configure(const ParameterSet& parameters); - - void setBaselineFits(const std::string& baselineFits,const std::string& baselineRun){ - baselineFits_ = baselineFits; - baselineRun_ = baselineRun; - }; - - - private: - - ClusterHistos* clusterHistos{nullptr}; - - std::string baselineFits_{""}; - std::string baselineRun_{""}; - - //TODO Change this to be held from HPSEvent - TTree* tree_; - std::vector *tracks_{}; - TBranch* btracks_{nullptr}; - std::vector hits_{}; - TBranch* bhits_{nullptr}; - TFile* outF_{nullptr}; - + public: + + ClusterOnTrackAnaProcessor(const std::string& name, Process& process); + + ~ClusterOnTrackAnaProcessor(); + + virtual bool process(IEvent* ievent); + + virtual void initialize(TTree* tree); + + virtual void finalize(); + + virtual void configure(const ParameterSet& parameters); + + void setBaselineFits(const std::string& baselineFits,const std::string& baselineRun){ + baselineFits_ = baselineFits; + baselineRun_ = baselineRun; + }; + + + private: + + ClusterHistos* clusterHistos{nullptr}; + + std::string baselineFits_{""}; + std::string baselineRun_{""}; + + //TODO Change this to be held from HPSEvent + TTree* tree_; + std::vector *tracks_{}; + TBranch* btracks_{nullptr}; + std::vector hits_{}; + TBranch* bhits_{nullptr}; + TFile* outF_{nullptr}; + }; diff --git a/processors/src/ClusterOnTrackAnaProcessor.cxx b/processors/src/ClusterOnTrackAnaProcessor.cxx index fcadd40af..20e7081e5 100644 --- a/processors/src/ClusterOnTrackAnaProcessor.cxx +++ b/processors/src/ClusterOnTrackAnaProcessor.cxx @@ -7,56 +7,56 @@ ClusterOnTrackAnaProcessor::~ClusterOnTrackAnaProcessor(){} void ClusterOnTrackAnaProcessor::configure(const ParameterSet& parameters) { - - baselineFits_ = parameters.getString("BaselineFits"); - baselineRun_ = parameters.getString("BaselineRun"); - std::cout<<"Configured: "<setBaselineFitsDir(baselineFits_); - if (!clusterHistos->LoadBaselineHistos(baselineRun_)) - std::cout<<"WARNING: baselines not loaded in Cluster on Track histos."<Define1DHistos(); - clusterHistos->Define2DHistos(); - tree_= tree; - //TODO Change this. - tree_->SetBranchAddress("GBLTracks",&tracks_,&btracks_); - //TODO Change this. - //outF_ = new TFile("outputFile.root","recreate"); - + clusterHistos = new ClusterHistos("hitOnTrack_2D"); + + if (!baselineFits_.empty() && !baselineRun_.empty()) { + clusterHistos->setBaselineFitsDir(baselineFits_); + if (!clusterHistos->LoadBaselineHistos(baselineRun_)) + std::cout<<"WARNING: baselines not loaded in Cluster on Track histos."<Define1DHistos(); + clusterHistos->Define2DHistos(); + tree_= tree; + //TODO Change this. + tree_->SetBranchAddress("GBLTracks",&tracks_,&btracks_); + //TODO Change this. + //outF_ = new TFile("outputFile.root","recreate"); + } bool ClusterOnTrackAnaProcessor::process(IEvent* ievent) { - - for (int itrack = 0; itracksize();itrack++) { - Track *track = tracks_->at(itrack); - //Loop on hits - if (!track->getSvtHits()) { - std::cout<<"WARNING::track doesn't have hits associated to it"<getSvtHits()->GetEntries(); ++ihit) { - TrackerHit* hit3d = (TrackerHit*) track->getSvtHits()->At(ihit); - clusterHistos->FillHistograms(hit3d,1.); + + for (int itrack = 0; itracksize();itrack++) { + Track *track = tracks_->at(itrack); + //Loop on hits + if (!track->getSvtHits()) { + std::cout<<"WARNING::track doesn't have hits associated to it"<getSvtHits()->GetEntries(); ++ihit) { + TrackerHit* hit3d = (TrackerHit*) track->getSvtHits()->At(ihit); + clusterHistos->FillHistograms(hit3d,1.); + } } - } - return true; + return true; } void ClusterOnTrackAnaProcessor::finalize() { - clusterHistos->saveHistos(outF_,""); - //outF_->Close(); - delete clusterHistos; - clusterHistos = nullptr; + clusterHistos->saveHistos(outF_,""); + //outF_->Close(); + delete clusterHistos; + clusterHistos = nullptr; } DECLARE_PROCESSOR(ClusterOnTrackAnaProcessor); From c9d1e1ce13668dc93fd5d0f00865bf8d783d3399 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 18 Oct 2019 20:37:24 -0400 Subject: [PATCH 145/314] Make Python3 compatible and fix bugs in ConfigurePython.cxx. Move executable code to execs dir --- CMakeLists.txt | 5 +- execs/CMakeLists.txt | 8 ++ .../include/ConfigurePython.h | 0 {processing => execs}/src/ConfigurePython.cxx | 108 +++++++++++++++--- {processing => execs}/src/hpstr.cxx | 6 +- processing/CMakeLists.txt | 9 +- processing/include/Process.h | 5 +- processing/include/ProcessorFactory.h | 25 ++-- processing/include/processingDef.h | 10 ++ processing/include/processingLinkDef.h | 19 +++ processing/python/HpstrConf.py | 28 ++--- processing/src/Process.cxx | 2 + processing/src/ProcessorFactory.cxx | 2 + 13 files changed, 181 insertions(+), 46 deletions(-) create mode 100644 execs/CMakeLists.txt rename {processing => execs}/include/ConfigurePython.h (100%) rename {processing => execs}/src/ConfigurePython.cxx (66%) rename {processing => execs}/src/hpstr.cxx (98%) create mode 100644 processing/include/processingDef.h create mode 100644 processing/include/processingLinkDef.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 729a19110..18b61f57f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,8 @@ endif() find_package(LCIO REQUIRED) # find Python installation -find_package(PythonLibs 2.7 REQUIRED) +# find_package(PythonLibs 2.7 REQUIRED) +find_package(PythonLibs REQUIRED) message(STATUS "Python lib found at: ${PYTHON_LIBRARIES}") message(STATUS "Python include dir found at: ${PYTHON_INCLUDE_DIRS}") get_filename_component(PYTHON_LIBRARY_DIR ${PYTHON_LIBRARIES} DIRECTORY) @@ -60,7 +61,7 @@ include(MacroModule) # import macro for declaring external dependencies include(MacroExtDeps) -set(MODULES event analysis processing processors) +set(MODULES event analysis processing processors execs) # build each module in the list foreach(module ${MODULES}) diff --git a/execs/CMakeLists.txt b/execs/CMakeLists.txt new file mode 100644 index 000000000..12cc52064 --- /dev/null +++ b/execs/CMakeLists.txt @@ -0,0 +1,8 @@ + +# Declare processing module +module( + NAME hpstrexecs + EXECUTABLES src/hpstr.cxx + DEPENDENCIES event processing + EXTERNAL_DEPENDENCIES ROOT Python LCIO +) diff --git a/processing/include/ConfigurePython.h b/execs/include/ConfigurePython.h similarity index 100% rename from processing/include/ConfigurePython.h rename to execs/include/ConfigurePython.h diff --git a/processing/src/ConfigurePython.cxx b/execs/src/ConfigurePython.cxx similarity index 66% rename from processing/src/ConfigurePython.cxx rename to execs/src/ConfigurePython.cxx index 24884e3eb..cd5ac5cc5 100644 --- a/processing/src/ConfigurePython.cxx +++ b/execs/src/ConfigurePython.cxx @@ -12,7 +12,13 @@ static std::string stringMember(PyObject* owner, const std::string& name) { std::string retval; PyObject* temp = PyObject_GetAttrString(owner, name.c_str()); if (temp != 0) { +#if PY_MAJOR_VERSION >= 3 + PyObject* pyStr = PyUnicode_AsEncodedString(temp, "utf-8","Error ~"); + retval = PyBytes_AS_STRING(pyStr); + Py_XDECREF(pyStr); +#else retval = PyString_AsString(temp); +#endif Py_DECREF(temp); } return retval; @@ -24,7 +30,7 @@ static long intMember(PyObject* owner, const std::string& name) { long retval; PyObject* temp = PyObject_GetAttrString(owner, name.c_str()); if (temp != 0) { - retval = PyInt_AsLong(temp); + retval = PyLong_AsLong(temp); Py_DECREF(temp); } return retval; @@ -50,12 +56,23 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], // executed. Note that the first parameter in the list or arguments // should refer to the script to be executed. if (nargs > 0) { - char** targs = new char*[nargs + 1]; - targs[0] = (char*) python_script.c_str(); - for (int i = 0; i < nargs; i++) - targs[i + 1] = args[i]; - PySys_SetArgvEx(nargs, targs, 1); - delete[] targs; +#if PY_MAJOR_VERSION >= 3 + wchar_t** targs = new wchar_t*[nargs + 1]; + targs[0] = Py_DecodeLocale(python_script.c_str(),NULL); + for (int i = 0; i < nargs; i++) + targs[i + 1] = Py_DecodeLocale(args[i],NULL); + + PySys_SetArgv(nargs+1, targs); + delete[] targs; +#else + char** targs = new char*[nargs + 1]; + targs[0] = (char*) python_script.c_str(); + for (int i = 0; i < nargs; i++) + targs[i + 1] = args[i]; + + PySys_SetArgvEx(nargs+1, targs, 1); + delete[] targs; +#endif } PyObject* script = nullptr; @@ -63,20 +80,20 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], PyObject* p_main = nullptr; PyObject* py_list = nullptr; PyObject* p_process = nullptr; - - // Load the python script. - script = PyImport_ImportModule(cmd.c_str()); - Py_DECREF(script); try { - + // Load the python script. + script = PyImport_ImportModule(cmd.c_str()); + // If a reference to the python script couldn't be created, raise // an exception. - if (script == 0) { + if (script == 0) { PyErr_Print(); throw std::runtime_error("[ ConfigurePython ]: Problem loading python script."); } + Py_DECREF(script); + // Load the script that is used create a processor PyObject* pCMod = PyObject_GetAttrString(script, "HpstrConf"); if (pCMod == 0) { @@ -118,6 +135,50 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], Py_ssize_t pos = 0; while (PyDict_Next(params, &pos, &key, &value)) { +#if PY_MAJOR_VERSION >= 3 + PyObject* pyStr = PyUnicode_AsEncodedString(key, "utf-8","Error ~"); + std::string skey = PyBytes_AS_STRING(pyStr); + + if (PyLong_Check(value)) { + pi.params_.insert(skey, int(PyLong_AsLong(value))); + //printf("Int Key: %s\n",skey.c_str()); + } else if (PyFloat_Check(value)) { + pi.params_.insert(skey, PyFloat_AsDouble(value)); + //printf("Double Key: %s\n",skey.c_str()); + } else if (PyUnicode_Check(value)) { + PyObject* pyStr = PyUnicode_AsEncodedString(value, "utf-8","Error ~"); + pi.params_.insert(skey, PyBytes_AS_STRING(pyStr)); + Py_XDECREF(pyStr); + //printf("String Key: %s\n",skey.c_str()); + } else if (PyList_Check(value)) { // assume everything is same value as first value + if (PyList_Size(value) > 0) { + PyObject* vec0 = PyList_GetItem(value, 0); + if (PyLong_Check(vec0)) { + std::vector vals; + for (Py_ssize_t j = 0; j < PyList_Size(value); j++) + vals.push_back(PyLong_AsLong(PyList_GetItem(value, j))); + pi.params_.insert(skey, vals); + //printf("VInt Key: %s\n",skey.c_str()); + } else if (PyFloat_Check(vec0)) { + std::vector vals; + for (Py_ssize_t j = 0; j < PyList_Size(value); j++) + vals.push_back(PyFloat_AsDouble(PyList_GetItem(value, j))); + pi.params_.insert(skey, vals); + //printf("VDouble Key: %s\n",skey.c_str()); + } else if (PyUnicode_Check(vec0)) { + std::vector vals; + for (Py_ssize_t j = 0; j < PyList_Size(value); j++){ + PyObject* pyStr = PyUnicode_AsEncodedString(PyList_GetItem(value, j), "utf-8","Error ~"); + vals.push_back( PyBytes_AS_STRING(pyStr)); + Py_XDECREF(pyStr); + } + pi.params_.insert(skey, vals); + //printf("VString Key: %s\n",skey.c_str()); + } + } + } + +#else std::string skey = PyString_AsString(key); if (PyInt_Check(value)) { pi.params_.insert(skey, int(PyInt_AsLong(value))); @@ -152,6 +213,7 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], } } } +#endif } } @@ -166,7 +228,13 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], } for (Py_ssize_t i = 0; i < PyList_Size(py_list); i++) { PyObject* elem = PyList_GetItem(py_list, i); +#if PY_MAJOR_VERSION >= 3 + PyObject* pyStr = PyUnicode_AsEncodedString(elem, "utf-8","Error ~"); + input_files_.push_back(PyBytes_AS_STRING(pyStr)); + Py_XDECREF(pyStr); +#else input_files_.push_back(PyString_AsString(elem)); +#endif } Py_DECREF(py_list); @@ -177,7 +245,13 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], } for (Py_ssize_t i = 0; i < PyList_Size(py_list); i++) { PyObject* elem = PyList_GetItem(py_list, i); +#if PY_MAJOR_VERSION >= 3 + PyObject* pyStr = PyUnicode_AsEncodedString(elem, "utf-8","Error ~"); + output_files_.push_back(PyBytes_AS_STRING(pyStr)); + Py_XDECREF(pyStr); +#else output_files_.push_back(PyString_AsString(elem)); +#endif } Py_DECREF(py_list); @@ -188,7 +262,13 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], } for (Py_ssize_t i = 0; i < PyList_Size(py_list); i++) { PyObject* elem = PyList_GetItem(py_list, i); - libraries_.push_back(PyString_AsString(elem)); +#if PY_MAJOR_VERSION >= 3 + PyObject* pyStr = PyUnicode_AsEncodedString(elem, "utf-8","Error ~"); + libraries_.push_back(PyBytes_AS_STRING(pyStr)); + Py_XDECREF(pyStr); +#else + libraries_.push_back(PyString_AsString(elem)); +#endif } Py_DECREF(py_list); diff --git a/processing/src/hpstr.cxx b/execs/src/hpstr.cxx similarity index 98% rename from processing/src/hpstr.cxx rename to execs/src/hpstr.cxx index 9a8be7152..979ba3b40 100644 --- a/processing/src/hpstr.cxx +++ b/execs/src/hpstr.cxx @@ -29,8 +29,6 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - bool processRoot = false; - int ptrpy = 1; for (ptrpy = 1; ptrpy < argc; ptrpy++) { std::cout << argv[ptrpy] << std::endl; @@ -47,8 +45,8 @@ int main(int argc, char **argv) { try { std::cout << "---- [ hpstr ]: Loading configuration --------" << std::endl; - - ConfigurePython cfg(argv[ptrpy], argv + ptrpy + 1, argc - ptrpy); + + ConfigurePython cfg(argv[ptrpy], argv + ptrpy + 1, argc - ptrpy -1); std::cout << "---- [ hpstr ]: Configuration load complete --------" << std::endl; diff --git a/processing/CMakeLists.txt b/processing/CMakeLists.txt index 9ca88da7f..de4f41169 100644 --- a/processing/CMakeLists.txt +++ b/processing/CMakeLists.txt @@ -1,8 +1,13 @@ # Declare processing module module( - NAME processing - EXECUTABLES src/hpstr.cxx + NAME processing + EXTRA_SOURCES processingDict.cxx DEPENDENCIES event EXTERNAL_DEPENDENCIES ROOT Python LCIO ) + +root_generate_dictionary(processingDict ${processing_INCLUDE_DIR}/processingDef.h MODULE ${PROJECT_NAME} LINKDEF ${processing_INCLUDE_DIR}/processingLinkDef.h) + +# install ROOT pcm file +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}_rdict.pcm DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) diff --git a/processing/include/Process.h b/processing/include/Process.h index f0c604b6b..7481f5d62 100644 --- a/processing/include/Process.h +++ b/processing/include/Process.h @@ -17,7 +17,8 @@ //----------// // ROOT // //----------// -#include +#include "TObject.h" +#include "TFile.h" //-----------// // hpstr // @@ -77,6 +78,7 @@ class Process { /** Check if the input_files_ are rootFiles */ bool processRootFiles(); + private: /** Reader used to parse either binary or EVIO files. */ @@ -94,6 +96,7 @@ class Process { /** List of output file names. If empty, no output file will be created. */ std::vector output_files_; + ClassDef(Process,1) }; #endif diff --git a/processing/include/ProcessorFactory.h b/processing/include/ProcessorFactory.h index 266363b41..06801e980 100644 --- a/processing/include/ProcessorFactory.h +++ b/processing/include/ProcessorFactory.h @@ -16,6 +16,10 @@ #include #include +//----------// +// ROOT // +//----------// +#include "TObject.h" // #include "Processor.h" @@ -63,21 +67,21 @@ class ProcessorFactory { * @param libname The library to load. */ void loadLibrary(const std::string& libname); + + /** + * @struct ProcessorInfo + * @brief Processor info container to hold classname, class type and maker. + */ + struct ProcessorInfo { + std::string classname; + ProcessorMaker* maker; + }; private: /** Constructor */ ProcessorFactory() {}; - /** - * @struct ProcessorInfo - * @brief Processor info container to hold classname, class type and maker. - */ - struct ProcessorInfo { - std::string classname; - ProcessorMaker* maker; - }; - /** A map of names to processor containers. */ std::map module_info_; @@ -85,6 +89,9 @@ class ProcessorFactory { /** A set of names of loaded libraries. */ std::set libs_loaded_; + + ClassDef(ProcessorFactory,1); + }; #endif // ProcessorFactory diff --git a/processing/include/processingDef.h b/processing/include/processingDef.h new file mode 100644 index 000000000..b87919f85 --- /dev/null +++ b/processing/include/processingDef.h @@ -0,0 +1,10 @@ +// +// ProcessDef.h +// hpstr +// +// Created by Maurik Holtrop on 10/17/19. +// + +#include "Process.h" +#include "ProcessorFactory.h" + diff --git a/processing/include/processingLinkDef.h b/processing/include/processingLinkDef.h new file mode 100644 index 000000000..3db97c1c7 --- /dev/null +++ b/processing/include/processingLinkDef.h @@ -0,0 +1,19 @@ +// +// ProcessLinkDef.h +// hpstr +// +// Created by Maurik Holtrop on 10/17/19. +// +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ nestedclasses; + +#pragma link C++ class Process+; +#pragma link C++ class ProcessorFactory+; + + +#endif diff --git a/processing/python/HpstrConf.py b/processing/python/HpstrConf.py index 705d34980..16de1b8dc 100644 --- a/processing/python/HpstrConf.py +++ b/processing/python/HpstrConf.py @@ -7,11 +7,11 @@ def __init__(self, instance_name, class_name): self.parameters = {} def toString(self): - print "\tProcessor( %s of instance %s )" % (self.instance_name, self.class_name) + print("\tProcessor( %s of instance %s )" % (self.instance_name, self.class_name)) if len(self.parameters) > 0: - print "\t\tParameters: " + print("\t\tParameters: ") for key, value in self.parameters.items(): - print "\t\t\t [ %s ]: %s" % (key, value) + print("\t\t\t [ %s ]: %s" % (key, value)) class Process: @@ -27,27 +27,27 @@ def __init__(self): def printProcess(self): - if (self.max_events > 0): print " Maximum events to process: %d" % (self.max_events) - else: " No limit on maximum events to process" + if (self.max_events > 0): print(" Maximum events to process: %d" % (self.max_events)) + else: print(" No limit on maximum events to process") - print "Processor sequence:" + print("Processor sequence:") for proc in self.sequence: proc.toString() if len(self.input_files) > 0: if len(self.output_files)==len(self.input_files): - print "Files:" + print("Files:") for i in range(0,len(self.input_files)): - print " '%s' -> '%s'"%(self.input_files[i],self.output_files[i]) + print (" '%s' -> '%s'"%(self.input_files[i],self.output_files[i])) else: - print "Input files:" + print("Input files:") for afile in self.input_files: - print " %s"%(afile) + print(" %s"%(afile)) if len(self.output_files) > 0: - print "Output file:", self.output_files[0] + print("Output file:", self.output_files[0]) elif len(self.output_files) > 0: - print "Output file:", self.output_files[0] + print("Output file:", self.output_files[0]) if len(self.libraries) > 0: - print "Shared libraries to load:" + print("Shared libraries to load:") for afile in self.libraries: - print " %s"%(afile) + print(" %s"%(afile)) diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 7f462a7e8..7c85b1666 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -8,6 +8,8 @@ #include "EventFile.h" #include "HpsEventFile.h" +ClassImp(Process) + Process::Process() {} //TODO Fix this better diff --git a/processing/src/ProcessorFactory.cxx b/processing/src/ProcessorFactory.cxx index 2bc845f92..ed5f91687 100644 --- a/processing/src/ProcessorFactory.cxx +++ b/processing/src/ProcessorFactory.cxx @@ -9,6 +9,8 @@ #include +ClassImp(ProcessorFactory) + void ProcessorFactory::registerProcessor(const std::string& classname, ProcessorMaker* maker) { auto ptr = module_info_.find(classname); if (ptr != module_info_.end()) { From 2d920d0e537bd62379d08facef1e250ae809ce6f Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 18 Oct 2019 21:08:01 -0400 Subject: [PATCH 146/314] Move the executable back into the libraries, on request. --- CMakeLists.txt | 2 +- execs/CMakeLists.txt | 8 -------- {execs => processing}/include/ConfigurePython.h | 0 {execs => processing}/src/ConfigurePython.cxx | 0 {execs => processing}/src/hpstr.cxx | 0 5 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 execs/CMakeLists.txt rename {execs => processing}/include/ConfigurePython.h (100%) rename {execs => processing}/src/ConfigurePython.cxx (100%) rename {execs => processing}/src/hpstr.cxx (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18b61f57f..4d97c8b41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ include(MacroModule) # import macro for declaring external dependencies include(MacroExtDeps) -set(MODULES event analysis processing processors execs) +set(MODULES event analysis processing processors) # build each module in the list foreach(module ${MODULES}) diff --git a/execs/CMakeLists.txt b/execs/CMakeLists.txt deleted file mode 100644 index 12cc52064..000000000 --- a/execs/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ - -# Declare processing module -module( - NAME hpstrexecs - EXECUTABLES src/hpstr.cxx - DEPENDENCIES event processing - EXTERNAL_DEPENDENCIES ROOT Python LCIO -) diff --git a/execs/include/ConfigurePython.h b/processing/include/ConfigurePython.h similarity index 100% rename from execs/include/ConfigurePython.h rename to processing/include/ConfigurePython.h diff --git a/execs/src/ConfigurePython.cxx b/processing/src/ConfigurePython.cxx similarity index 100% rename from execs/src/ConfigurePython.cxx rename to processing/src/ConfigurePython.cxx diff --git a/execs/src/hpstr.cxx b/processing/src/hpstr.cxx similarity index 100% rename from execs/src/hpstr.cxx rename to processing/src/hpstr.cxx From 1886636c239e326ca96ef9acee9419e14e523147 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 21 Oct 2019 14:56:14 -0700 Subject: [PATCH 147/314] Add MCTrackerHit to event --- event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 3 + event/include/MCTrackerHit.h | 112 +++++++++++++++++++++++++++++++++++ event/src/MCTrackerHit.cxx | 40 +++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 event/include/MCTrackerHit.h create mode 100644 event/src/MCTrackerHit.cxx diff --git a/event/include/EventDef.h b/event/include/EventDef.h index d21b624d8..4faec6a89 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -11,4 +11,5 @@ #include "Track.h" #include "Vertex.h" #include "TrackerHit.h" +#include "MCTrackerHit.h" #include "RawSvtHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index b4b09cd8b..d47d42f49 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -28,6 +28,7 @@ #pragma link C++ class Track+; #pragma link C++ class Vertex+; #pragma link C++ class TrackerHit+; +#pragma link C++ class MCTrackerHit+; #pragma link C++ class RawSvtHit+; // This is to create the dictionary for stl containers @@ -37,6 +38,8 @@ #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; diff --git a/event/include/MCTrackerHit.h b/event/include/MCTrackerHit.h new file mode 100644 index 000000000..f1f3f75ed --- /dev/null +++ b/event/include/MCTrackerHit.h @@ -0,0 +1,112 @@ +/** + * @file MCTrackerHit.h + * @brief Class used to encapsulate mc tracker hit information + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef _MCTRACKER_HIT_H_ +#define _MCTRACKER_HIT_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include +#include +#include + +class MCTrackerHit : public TObject { + + public: + + /** Constructor */ + MCTrackerHit(); + + /** Destructor */ + virtual ~MCTrackerHit(); + + /** Reset the Hit object. */ + void Clear(Option_t *option=""); + + /** + * Set the hit position. + * + * @param position The hit position. + */ + void setPosition(const double* position, bool rotate = false); + + /** @return The hit position. */ + std::vector getPosition() const { return {x_, y_, z_}; }; + + /** @return the global X coordinate of the hit */ + double getGlobalX() const {return x_;} + + /** @return the global X coordinate of the hit */ + double getGlobalY() const {return y_;} + + /** @return the global X coordinate of the hit */ + double getGlobalZ() const {return z_;} + + /** + * Set the hit time. + * + * @param time The hit time. + */ + void setTime(const double time) { time_ = time; }; + + /** @return The hit time. */ + double getTime() const { return time_; }; + + /** + * Set the hit energy deposit. + * + * @param charge The hit energy. + */ + void setEdep(const double edep) { edep_ = edep; }; + + /** @return The hit energy deposit. */ + double getEdep() const { return edep_; }; + + void setModule(const int module ) {module_ = module;} ; + + //** @return the tracker hit volume from the raw hit content */ + int getModule() { return module_;} ; + + //** set the tracker hit layer from the raw hit content */ + void setLayer(const int layer) {layer_ = layer;}; + + //** @return the tracker hit layer from the raw hit content */ + int getLayer() const {return layer_;}; + + ClassDef(MCTrackerHit, 1); + + private: + + /** The x position of the hit. */ + double x_{-999}; + + /** The x position of the hit. */ + double y_{-999}; + + /** The x position of the hit. */ + double z_{-999}; + + /** The hit time. */ + double time_{-999}; + + /** Layer (Axial + Stereo). 1-12 in 2015/2016 geometry, 1-14 in 2019 geometry */ + int layer_{-999}; + + /** Module */ + int module_{-999}; + + /** Raw charge: sum of the raw hit fit amplitudes */ + float edep_{-999}; + +}; // MCTrackerHit + +#endif // _MCTRACKER_HIT_H_ diff --git a/event/src/MCTrackerHit.cxx b/event/src/MCTrackerHit.cxx new file mode 100644 index 000000000..2726a4d2f --- /dev/null +++ b/event/src/MCTrackerHit.cxx @@ -0,0 +1,40 @@ +/** + * @file MCTrackerHit.cxx + * @brief Class used to encapsulate mc tracker hit information + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#include "MCTrackerHit.h" + +ClassImp(MCTrackerHit) + +MCTrackerHit::MCTrackerHit() + : TObject() { + } + +MCTrackerHit::~MCTrackerHit() { + Clear(); +} + +void MCTrackerHit::Clear(Option_t* /* options */) { + TObject::Clear(); +} + +void MCTrackerHit::setPosition(const double* position, bool rotate) { + + //svt angle: it's already with minus sign. + float svtAngle = 30.5e-3; + //Rotate the the input position automatically to match with the SVT tracker system + if (rotate) + { + //x_ = position[1]; + y_ = position[2]; + z_ = position[1] * sin(svtAngle) + position[0]*cos(svtAngle); + x_ = position[1] * cos(svtAngle) - position[0]*sin(svtAngle); + } + else { + x_ = position[0]; + y_ = position[1]; + z_ = position[2]; + } +} From a77ef8af95d4cd7a0754675cb631cf41a6ca7c40 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 21 Oct 2019 16:05:15 -0700 Subject: [PATCH 148/314] Add MCTrackerHitProcessor --- event/include/Collections.h | 3 + processors/include/MCTrackerHitProcessor.h | 77 ++++++++++++++++++++++ processors/src/MCTrackerHitProcessor.cxx | 68 +++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 processors/include/MCTrackerHitProcessor.h create mode 100644 processors/src/MCTrackerHitProcessor.cxx diff --git a/event/include/Collections.h b/event/include/Collections.h index cd0646714..d21226ca8 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -46,6 +46,9 @@ namespace Collections { /** Name of the collection containing MC Particles. */ constexpr const char* MC_PARTICLES{"MCParticle"}; + /** Name of the collection containing MC Particles. */ + constexpr const char* MC_TRACKER_HITS{"TrackerHits"}; + /** Name of time corrected ECal hits collection. */ constexpr const char* ECAL_TIME_CORR_HITS{"TimeCorrEcalHits"}; diff --git a/processors/include/MCTrackerHitProcessor.h b/processors/include/MCTrackerHitProcessor.h new file mode 100644 index 000000000..6b745714d --- /dev/null +++ b/processors/include/MCTrackerHitProcessor.h @@ -0,0 +1,77 @@ +/** + * + */ + +#ifndef __MCTRACKERHIT_PROCESSOR_H__ +#define __MCTRACKERHIT_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" +#include "TTree.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "MCTrackerHit.h" +#include "Event.h" + +class MCTrackerHitProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + MCTrackerHitProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~MCTrackerHitProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual bool process(IEvent* ievent); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(TTree* tree); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Container to hold all TrackerHit objects. */ + TClonesArray* trackerhits_{nullptr}; + +}; // MCTrackerHitProcessor + +#endif // __MCTRACKERHIT_PROCESSOR_H__ diff --git a/processors/src/MCTrackerHitProcessor.cxx b/processors/src/MCTrackerHitProcessor.cxx new file mode 100644 index 000000000..33c1a1b2b --- /dev/null +++ b/processors/src/MCTrackerHitProcessor.cxx @@ -0,0 +1,68 @@ +/** + * @file MCTrackerHitProcessor.h + * @brief Processor used to add simulated tracker hits to the event + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ +#include "MCTrackerHitProcessor.h" + +MCTrackerHitProcessor::MCTrackerHitProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +MCTrackerHitProcessor::~MCTrackerHitProcessor() { +} + +void MCTrackerHitProcessor::initialize(TTree* tree) { + + trackerhits_ = new TClonesArray("MCTrackerHit", 100000); + tree->Branch(Collections::MC_TRACKER_HITS,&trackerhits_); +} + +bool MCTrackerHitProcessor::process(IEvent* ievent) { + + Event* event = static_cast(ievent); + // Get the collection of simulated tracker hits from the LCIO event. + EVENT::LCCollection* lcio_trackerhits = event->getLCCollection(Collections::MC_TRACKER_HITS); + + // Get decoders to read cellids + UTIL::BitField64 decoder("system:0:6,barrel:6:3,layer:9:4,module:13:12,sensor:25:1,side:32:-2,strip:34:12"); + //decoder[field] returns the value + + // Loop over all of the raw SVT hits in the LCIO event and add them to the + // HPS event + trackerhits_->Clear(); + for (int ihit = 0; ihit < lcio_trackerhits->getNumberOfElements(); ++ihit) { + + // Get a 3D hit from the list of hits + EVENT::SimTrackerHit* lcio_mcTracker_hit + = static_cast(lcio_trackerhits->getElementAt(ihit)); + //Decode the cellid + EVENT::long64 value = EVENT::long64( lcio_mcTracker_hit->getCellID0() & 0xffffffff ) | + ( EVENT::long64( lcio_mcTracker_hit->getCellID1() ) << 32 ) ; + decoder.setValue(value); + + // Add a raw tracker hit to the event + MCTrackerHit* mc_tracker_hit = static_cast(trackerhits_->ConstructedAt(ihit)); + + // Set sensitive detector identification + mc_tracker_hit->setLayer(decoder["layer"]); + mc_tracker_hit->setModule(decoder["module"]); + + // Set the position of the hit + mc_tracker_hit->setPosition(lcio_mcTracker_hit->getPosition()); + + // Set the energy deposit of the hit + mc_tracker_hit->setEdep(lcio_mcTracker_hit->getEDep()); + + // Set the time of the hit + mc_tracker_hit->setTime(lcio_mcTracker_hit->getTime()); + + } + + return true; +} + +void MCTrackerHitProcessor::finalize() { +} + +DECLARE_PROCESSOR(MCTrackerHitProcessor); From 91c9b197dad6d0b7c5460f59beaeb6a7c2256282 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 21 Oct 2019 16:32:06 -0700 Subject: [PATCH 149/314] Fixing comments --- event/include/Collections.h | 2 +- event/include/MCTrackerHit.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/event/include/Collections.h b/event/include/Collections.h index d21226ca8..70ca3d8a1 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -46,7 +46,7 @@ namespace Collections { /** Name of the collection containing MC Particles. */ constexpr const char* MC_PARTICLES{"MCParticle"}; - /** Name of the collection containing MC Particles. */ + /** Name of the collection containing MC Tracker Hits. */ constexpr const char* MC_TRACKER_HITS{"TrackerHits"}; /** Name of time corrected ECal hits collection. */ diff --git a/event/include/MCTrackerHit.h b/event/include/MCTrackerHit.h index f1f3f75ed..5f4f9709d 100644 --- a/event/include/MCTrackerHit.h +++ b/event/include/MCTrackerHit.h @@ -104,7 +104,7 @@ class MCTrackerHit : public TObject { /** Module */ int module_{-999}; - /** Raw charge: sum of the raw hit fit amplitudes */ + /** Energy deposit of hit */ float edep_{-999}; }; // MCTrackerHit From 0cba40053bf2b065d7f777ee65eaafd6d4f53b21 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 21 Oct 2019 16:57:43 -0700 Subject: [PATCH 150/314] Add MCEcalHit to event --- event/include/EventDef.h | 1 + event/include/EventLinkDef.h | 3 + event/include/MCEcalHit.h | 134 +++++++++++++++++++++++++++++++++++ event/src/MCEcalHit.cxx | 39 ++++++++++ 4 files changed, 177 insertions(+) create mode 100644 event/include/MCEcalHit.h create mode 100644 event/src/MCEcalHit.cxx diff --git a/event/include/EventDef.h b/event/include/EventDef.h index 4faec6a89..3841c5c7f 100644 --- a/event/include/EventDef.h +++ b/event/include/EventDef.h @@ -12,4 +12,5 @@ #include "Vertex.h" #include "TrackerHit.h" #include "MCTrackerHit.h" +#include "MCEcalHit.h" #include "RawSvtHit.h" diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index d47d42f49..7376f19bc 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -29,6 +29,7 @@ #pragma link C++ class Vertex+; #pragma link C++ class TrackerHit+; #pragma link C++ class MCTrackerHit+; +#pragma link C++ class MCEcalHit+; #pragma link C++ class RawSvtHit+; // This is to create the dictionary for stl containers @@ -40,6 +41,8 @@ #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; diff --git a/event/include/MCEcalHit.h b/event/include/MCEcalHit.h new file mode 100644 index 000000000..6a3cd8750 --- /dev/null +++ b/event/include/MCEcalHit.h @@ -0,0 +1,134 @@ +/** + * @file MCEcalHit.h + * @brief Class used to encapsulate mc Ecal hit information + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef _MC_ECAL_HIT_H_ +#define _MC_ECAL_HIT_H_ + +//----------------// +// C++ StdLib // +//----------------// +#include + +//----------// +// ROOT // +//----------// +#include +#include +#include + +class MCEcalHit : public TObject { + + public: + + /** Constructor */ + MCEcalHit(); + + /** Destructor */ + virtual ~MCEcalHit(); + + /** Reset the Hit object. */ + void Clear(Option_t *option=""); + + /** + * Set the hit position. + * + * @param position The hit position. + */ + void setPosition(const double* position, bool rotate = false); + + /** @return The hit position. */ + std::vector getPosition() const { return {x_, y_, z_}; }; + + /** @return the global X coordinate of the hit */ + double getGlobalX() const {return x_;} + + /** @return the global Y coordinate of the hit */ + double getGlobalY() const {return y_;} + + /** @return the global Z coordinate of the hit */ + double getGlobalZ() const {return z_;} + + /** + * Set the hit energy deposit. + * + * @param energy The hit energy. + */ + void setEnergy(const double energy) { energy_ = energy; }; + + /** @return The hit energy deposit. */ + double getEnergy() const { return energy_; }; + + /** + * Set the system of the hit. + * + * @param system The system of the hit. + */ + void setSystem(const int system ) {system_ = system;} ; + + //** @return the Ecal hit system */ + int getSystem() { return system_;} ; + + /** + * Set the layer of the hit. + * + * @param layer The layer of the hit. + */ + void setLayer(const int layer) {layer_ = layer;}; + + //** @return the Ecal hit layer from the raw hit content */ + int getLayer() const {return layer_;}; + + /** + * Set the x index of the hit. + * + * @param layer The x index of the hit. + */ + void setIX(const int ix) {ix_ = ix;}; + + //** @return the y index of the hit. */ + int getIX() const {return ix_;}; + + /** + * Set the y index of the hit. + * + * @param layer The y index of the hit. + */ + void setIY(const int iy) {iy_ = iy;}; + + //** @return the y index of the hit. */ + int getIY() const {return iy_;}; + + ClassDef(MCEcalHit, 1); + + private: + + /** The x position of the hit. */ + double x_{-999}; + + /** The x position of the hit. */ + double y_{-999}; + + /** The x position of the hit. */ + double z_{-999}; + + /** System */ + int system_{-999}; + + /** Layer */ + int layer_{-999}; + + /** X index of crystal */ + int ix_{-999}; + + /** Y index of crystal */ + int iy_{-999}; + + /** Energy of hit */ + float energy_{-999}; + +}; // MCEcalHit + +#endif // _MC_ECAL_HIT_H_ diff --git a/event/src/MCEcalHit.cxx b/event/src/MCEcalHit.cxx new file mode 100644 index 000000000..ae05e56f2 --- /dev/null +++ b/event/src/MCEcalHit.cxx @@ -0,0 +1,39 @@ +/** + * @file MCEcalHit.cxx + * @brief Class used to encapsulate mc tracker hit information + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#include "MCEcalHit.h" + +ClassImp(MCEcalHit) + +MCEcalHit::MCEcalHit() + : TObject() { + } + +MCEcalHit::~MCEcalHit() { + Clear(); +} + +void MCEcalHit::Clear(Option_t* /* options */) { + TObject::Clear(); +} + +void MCEcalHit::setPosition(const double* position, bool rotate) { + + //svt angle: it's already with minus sign. + float svtAngle = 30.5e-3; + //Rotate the the input position automatically to match with the SVT tracker system + if (rotate) + { + y_ = position[2]; + z_ = position[1] * sin(svtAngle) + position[0]*cos(svtAngle); + x_ = position[1] * cos(svtAngle) - position[0]*sin(svtAngle); + } + else { + x_ = position[0]; + y_ = position[1]; + z_ = position[2]; + } +} From 7a48a89d1721a884d8087c8400cb3a58f022c055 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 21 Oct 2019 17:28:01 -0700 Subject: [PATCH 151/314] Add MCEcalHitProcessor --- event/include/Collections.h | 3 + processors/include/MCEcalHitProcessor.h | 79 +++++++++++++++++++++++++ processors/src/MCEcalHitProcessor.cxx | 69 +++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 processors/include/MCEcalHitProcessor.h create mode 100644 processors/src/MCEcalHitProcessor.cxx diff --git a/event/include/Collections.h b/event/include/Collections.h index d21226ca8..12031489a 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -55,6 +55,9 @@ namespace Collections { /** Name of ECal hits collection. */ constexpr const char* ECAL_HITS{"EcalCalHits"}; + /** Name of simulated ECal hits collection. */ + constexpr const char* MC_ECAL_HITS{"EcalHits"}; + /** Name of ECal clusters collection. */ constexpr const char* ECAL_CLUSTERS{"EcalClustersCorr"}; diff --git a/processors/include/MCEcalHitProcessor.h b/processors/include/MCEcalHitProcessor.h new file mode 100644 index 000000000..9fef12732 --- /dev/null +++ b/processors/include/MCEcalHitProcessor.h @@ -0,0 +1,79 @@ +/** + * @file MCEcalHitProcessor.h + * @brief Processor used to add simulated ecal hits to the event + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ + +#ifndef __MCECALHIT_PROCESSOR_H__ +#define __MCECALHIT_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include + +//----------// +// ROOT // +//----------// +#include "TClonesArray.h" +#include "TTree.h" + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "MCEcalHit.h" +#include "Event.h" + +class MCEcalHitProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + MCEcalHitProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~MCEcalHitProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual bool process(IEvent* ievent); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(TTree* tree); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Container to hold all MCEcalHit objects. */ + TClonesArray* ecalhits_{nullptr}; + +}; // MCEcalHitProcessor + +#endif // __MCECALHIT_PROCESSOR_H__ diff --git a/processors/src/MCEcalHitProcessor.cxx b/processors/src/MCEcalHitProcessor.cxx new file mode 100644 index 000000000..75d3acec7 --- /dev/null +++ b/processors/src/MCEcalHitProcessor.cxx @@ -0,0 +1,69 @@ +/** + * @file MCEcalHitProcessor.cxx + * @brief Processor used to add simulated ecal hits to the event + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ +#include "MCEcalHitProcessor.h" + +MCEcalHitProcessor::MCEcalHitProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +MCEcalHitProcessor::~MCEcalHitProcessor() { +} + +void MCEcalHitProcessor::initialize(TTree* tree) { + + ecalhits_ = new TClonesArray("MCEcalHit", 100000); + tree->Branch(Collections::MC_ECAL_HITS,&ecalhits_); +} + +bool MCEcalHitProcessor::process(IEvent* ievent) { + + Event* event = static_cast(ievent); + // Get the collection of simulated ecal hits from the LCIO event. + EVENT::LCCollection* lcio_ecalhits = event->getLCCollection(Collections::MC_ECAL_HITS); + + // Get decoders to read cellids + UTIL::BitField64 decoder("system:0:6,layer:6:2,ix:8:-8,iy:16:-6"); + //decoder[field] returns the value + + // Loop over all of the raw SVT hits in the LCIO event and add them to the + // HPS event + ecalhits_->Clear(); + for (int ihit = 0; ihit < lcio_ecalhits->getNumberOfElements(); ++ihit) { + + // Get a 3D hit from the list of hits + EVENT::SimCalorimeterHit* lcio_mcEcal_hit + = static_cast(lcio_ecalhits->getElementAt(ihit)); + //Decode the cellid + EVENT::long64 value = EVENT::long64( lcio_mcEcal_hit->getCellID0() & 0xffffffff ) | + ( EVENT::long64( lcio_mcEcal_hit->getCellID1() ) << 32 ) ; + decoder.setValue(value); + + // Add a mc ecal hit to the event + MCEcalHit* mc_ecal_hit = static_cast(ecalhits_->ConstructedAt(ihit)); + + // Set sensitive detector identification + mc_ecal_hit->setSystem(decoder["system"]); + mc_ecal_hit->setLayer(decoder["layer"]); + mc_ecal_hit->setIX(decoder["ix"]); + mc_ecal_hit->setIY(decoder["iy"]); + + // Set the position of the hit, dealing with it being a float and not double + const float hitPosF[3] = {lcio_mcEcal_hit->getPosition()[0], lcio_mcEcal_hit->getPosition()[1], lcio_mcEcal_hit->getPosition()[2]}; + double hitPosD[3] = {(double)hitPosF[0], (double)hitPosF[1], (double)hitPosF[2]}; + mc_ecal_hit->setPosition(hitPosD); + + // Set the energy deposit of the hit + mc_ecal_hit->setEnergy(lcio_mcEcal_hit->getEnergy()); + + } + + return true; +} + +void MCEcalHitProcessor::finalize() { +} + +DECLARE_PROCESSOR(MCEcalHitProcessor); From 1da05d4b296a9d4798d59957fdfef2fbc63a6cca Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 24 Oct 2019 10:58:58 -0700 Subject: [PATCH 152/314] Adding MCAnaProcessor and clean up MCProcessors --- analysis/include/HistoManager.h | 7 ++- analysis/include/MCAnaHistos.h | 31 ++++++++++ analysis/src/HistoManager.cxx | 10 ++++ analysis/src/MCAnaHistos.cxx | 70 ++++++++++++++++++++++ event/include/MCTrackerHit.h | 9 +++ processors/include/MCAnaProcessor.h | 56 +++++++++++++++++ processors/include/MCTrackerHitProcessor.h | 1 + processors/src/MCAnaProcessor.cxx | 56 +++++++++++++++++ processors/src/MCTrackerHitProcessor.cxx | 3 + processors/src/SvtRawDataProcessor.cxx | 2 +- 10 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 analysis/include/MCAnaHistos.h create mode 100644 analysis/src/MCAnaHistos.cxx create mode 100644 processors/include/MCAnaProcessor.h create mode 100644 processors/src/MCAnaProcessor.cxx diff --git a/analysis/include/HistoManager.h b/analysis/include/HistoManager.h index 93798d0c2..50901e3b6 100644 --- a/analysis/include/HistoManager.h +++ b/analysis/include/HistoManager.h @@ -13,8 +13,8 @@ class HistoManager { public: - HistoManager() {m_name = "default";} - HistoManager(const std::string& inputName) {m_name=inputName;}; + HistoManager(); + HistoManager(const std::string& inputName); virtual ~HistoManager(); @@ -67,6 +67,7 @@ class HistoManager { virtual void Define2DHistos(){}; virtual void Define1DHistos(){}; + virtual void FillEvent(){event_h->Fill(0.0);}; virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder = ""); @@ -91,6 +92,8 @@ class HistoManager { std::map histos3d; typedef std::map::iterator it3d; + TH1D * event_h; + bool debug_{false}; }; diff --git a/analysis/include/MCAnaHistos.h b/analysis/include/MCAnaHistos.h new file mode 100644 index 000000000..3d9384ede --- /dev/null +++ b/analysis/include/MCAnaHistos.h @@ -0,0 +1,31 @@ +#ifndef MCANAHISTOS_H +#define MCANAHISTOS_H + +// ROOT +#include "TClonesArray.h" + +// HPSTR +#include "HistoManager.h" +#include "MCParticle.h" +#include "MCTrackerHit.h" +#include "MCEcalHit.h" +#include +#include + +class MCAnaHistos : public HistoManager { + + public: + + MCAnaHistos(const std::string& inputName) : HistoManager(inputName) { m_name = inputName; }; + + virtual void Define3DHistos(){}; + virtual void Define2DHistos(){}; + virtual void Define1DHistos(); + + void FillMCParticles(TClonesArray* mcParts, float weight = 1.); + void FillMCTrackerHits(TClonesArray* mcTrkrHits, float weight = 1.); + void FillMCEcalHits(TClonesArray* mcEcalHits, float weight = 1.); + +}; + +#endif //MCANAHISTOS_H diff --git a/analysis/src/HistoManager.cxx b/analysis/src/HistoManager.cxx index 44fbaf565..881d12a74 100644 --- a/analysis/src/HistoManager.cxx +++ b/analysis/src/HistoManager.cxx @@ -3,6 +3,14 @@ #include "TKey.h" #include "TClass.h" +HistoManager::HistoManager() { + HistoManager("default"); +} + +HistoManager::HistoManager(const std::string& inputName) { + m_name = inputName; + event_h = new TH1D("event_h","Number of Events Processed;;Events", 21, -10.5, 10.5); +} HistoManager::~HistoManager() { @@ -204,6 +212,8 @@ void HistoManager::saveHistos(TFile* outF,std::string folder) { dir->cd(); } + event_h->Write(); + for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { if (!it->second){ std::cout<first<<" Null ptr in saving.."< + +void MCAnaHistos::Define1DHistos() { + + // init MCParticle Histos + histos1d["numMCparts_h"] = new TH1F("numMCparts_h", ";Number of Sim Particles;Events", + 60, -0.5, 59.5); + histos1d["MCpartsEnergy_h"] = new TH1F("MCpartsEnergy_h", ";Energy of Sim Particle [GeV];Sim Particles / 10 MeV", + 450, 0, 4.5); + histos1d["MCpartsEnergyLow_h"] = new TH1F("MCpartsEnergyLow_h", ";Energy of Sim Particle [MeV];Sim Particles / 1 MeV", + 200, 0, 200); + histos1d["minMuonE_h"] = new TH1F("minMuonE_h", "Minimum MC Muon Energy;Energy [GeV];Sim Particles / 10 MeV", + 450, 0, 4.5); + + // init MCTrackerHit Histos + histos1d["numMCTrkrHit_h"] = new TH1F("numMCTrkrHit_h", ";Number of Sim Tracker Hits;Events", + 30, -0.5, 29.5); + histos1d["mcTrkrHitEdep_h"] = new TH1F("mcTrkrHitEdep_h", ";Tracker Hit Energy [MeV];Sim Particles / 1 MeV", + 10, 0, 10); + histos1d["mcTrkrHitPdgId_h"] = new TH1F("mcTrkrHitPdgId_h", ";PDG ID;Sim Particles", + 101, -50.5, 50.5); + + // init MCEcalHit Histos + histos1d["numMCEcalHit_h"] = new TH1F("numMCEcalHit_h", ";Number of Sim Ecal Hits;Events", + 60, -0.5, 59.5); + histos1d["mcEcalHitEnergy_h"] = new TH1F("mcEcalHitEnergy_h", ";Ecal Hit Energy [MeV];Sim Particles / 2 MeV", + 200, 0, 400); +} + +void MCAnaHistos::FillMCParticles(TClonesArray* mcParts, float weight ) { + int nParts = mcParts->GetEntriesFast(); + histos1d["numMCparts_h"]->Fill((float)nParts, weight); + double minMuonE = -99.9; + for (int i=0; i < nParts; i++) + { + MCParticle *part = (MCParticle*)mcParts->At(i); + int pdg = part->getPDG(); + double energy = part->getEnergy(); + if ((fabs(pdg) == 13) && (energy < minMuonE || minMuonE < 0.0)) + { + minMuonE = energy; + } + histos1d["MCpartsEnergy_h"]->Fill(energy, weight); + histos1d["MCpartsEnergyLow_h"]->Fill(energy*1000.0, weight);// Scaled to MeV + } + histos1d["minMuonE_h"]->Fill(minMuonE, weight); +} + +void MCAnaHistos::FillMCTrackerHits(TClonesArray* mcTrkrHits, float weight ) { + int nHits = mcTrkrHits->GetEntriesFast(); + histos1d["numMCTrkrHit_h"]->Fill(nHits, weight); + for (int i=0; i < nHits; i++) + { + MCTrackerHit *hit = (MCTrackerHit*)mcTrkrHits->At(i); + int pdg = hit->getPDG(); + histos1d["mcTrkrHitEdep_h"]->Fill(hit->getEdep()*1000.0, weight); // Scaled to MeV + histos1d["mcTrkrHitPdgId_h"]->Fill((float)hit->getPDG(), weight); + } +} + +void MCAnaHistos::FillMCEcalHits(TClonesArray* mcEcalHits, float weight ) { + int nHits = mcEcalHits->GetEntriesFast(); + histos1d["numMCEcalHit_h"]->Fill(nHits, weight); + for (int i=0; i < nHits; i++) + { + MCEcalHit *hit = (MCEcalHit*)mcEcalHits->At(i); + histos1d["mcEcalHitEnergy_h"]->Fill(hit->getEnergy()*1000.0, weight); // Scaled to MeV + } +} diff --git a/event/include/MCTrackerHit.h b/event/include/MCTrackerHit.h index f1f3f75ed..41ce3e086 100644 --- a/event/include/MCTrackerHit.h +++ b/event/include/MCTrackerHit.h @@ -82,6 +82,12 @@ class MCTrackerHit : public TObject { //** @return the tracker hit layer from the raw hit content */ int getLayer() const {return layer_;}; + //** set the pdg id of particle that made the hit */ + void setPDG(const int pdg) {pdg_ = pdg;}; + + //** @return the pdg id of particle that made the hit */ + int getPDG() const {return pdg_;}; + ClassDef(MCTrackerHit, 1); private: @@ -107,6 +113,9 @@ class MCTrackerHit : public TObject { /** Raw charge: sum of the raw hit fit amplitudes */ float edep_{-999}; + /** pdg id of particle that made the hit */ + int pdg_{-999}; + }; // MCTrackerHit #endif // _MCTRACKER_HIT_H_ diff --git a/processors/include/MCAnaProcessor.h b/processors/include/MCAnaProcessor.h new file mode 100644 index 000000000..6c78c6b6c --- /dev/null +++ b/processors/include/MCAnaProcessor.h @@ -0,0 +1,56 @@ +#ifndef __MC_ANAPROCESSOR_H__ +#define __MC_ANAPROCESSOR_H__ + +//HPSTR +#include "HpsEvent.h" +#include "Collections.h" +#include "MCParticle.h" +#include "MCTrackerHit.h" +#include "MCEcalHit.h" +#include "MCAnaHistos.h" + + +//ROOT +#include "Processor.h" +#include "TClonesArray.h" +#include "TBranch.h" +#include "TTree.h" +#include "TFile.h" + +class TTree; + + +class MCAnaProcessor : public Processor { + + public: + + MCAnaProcessor(const std::string& name, Process& process); + + ~MCAnaProcessor(); + + virtual bool process(IEvent* ievent); + + virtual void initialize(TTree* tree); + + virtual void finalize(); + + virtual void configure(const ParameterSet& parameters); + + private: + + MCAnaHistos* histos{nullptr}; + + //TODO Change this to be held from HPSEvent + TTree* tree_; + TBranch* bmcParts_{nullptr}; + TBranch* bmcTrkrHits_{nullptr}; + TBranch* bmcEcalHits_{nullptr}; + TClonesArray* mcParts_{nullptr}; + TClonesArray* mcTrkrHits_{nullptr}; + TClonesArray* mcEcalHits_{nullptr}; + TFile* outF_{nullptr}; + +}; + + +#endif diff --git a/processors/include/MCTrackerHitProcessor.h b/processors/include/MCTrackerHitProcessor.h index 6b745714d..459d125eb 100644 --- a/processors/include/MCTrackerHitProcessor.h +++ b/processors/include/MCTrackerHitProcessor.h @@ -17,6 +17,7 @@ //----------// #include #include +#include #include //----------// diff --git a/processors/src/MCAnaProcessor.cxx b/processors/src/MCAnaProcessor.cxx new file mode 100644 index 000000000..3de4a7f1a --- /dev/null +++ b/processors/src/MCAnaProcessor.cxx @@ -0,0 +1,56 @@ +/** + * @file MCAnaProcessor.cxx + * @brief AnaProcessor used fill histograms to compare simulations + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ +#include "MCAnaProcessor.h" +#include + +MCAnaProcessor::MCAnaProcessor(const std::string& name, Process& process) : Processor(name,process){} +//TODO CHECK THIS DESTRUCTOR +MCAnaProcessor::~MCAnaProcessor(){} + + +void MCAnaProcessor::configure(const ParameterSet& parameters) { + +} + +void MCAnaProcessor::initialize(TTree* tree) { + tree_= tree; + // init histos + histos = new MCAnaHistos("hitOnTrack_2D"); + histos->Define1DHistos(); + histos->Define2DHistos(); + + // init TClonesArrays + mcParts_ = new TClonesArray("MCParticle" , 1000000); + mcTrkrHits_ = new TClonesArray("MCTrackerHit", 1000000); + mcEcalHits_ = new TClonesArray("MCEcalHit" , 1000000); + + // init TTree + tree_->SetBranchAddress(Collections::MC_PARTICLES, &mcParts_, &bmcParts_); + tree_->SetBranchAddress(Collections::MC_TRACKER_HITS, &mcTrkrHits_, &bmcTrkrHits_); + tree_->SetBranchAddress(Collections::MC_ECAL_HITS, &mcEcalHits_, &bmcEcalHits_); + +} + +bool MCAnaProcessor::process(IEvent* ievent) { + + histos->FillEvent(); + histos->FillMCParticles(mcParts_); + histos->FillMCTrackerHits(mcTrkrHits_); + histos->FillMCEcalHits(mcEcalHits_); + + return true; +} + +void MCAnaProcessor::finalize() { + + outF_ = new TFile("testMCAnaHistos.root","RECREATE"); + histos->saveHistos(outF_,""); + outF_->Close(); + delete histos; + histos = nullptr; +} + +DECLARE_PROCESSOR(MCAnaProcessor); diff --git a/processors/src/MCTrackerHitProcessor.cxx b/processors/src/MCTrackerHitProcessor.cxx index 33c1a1b2b..96692a841 100644 --- a/processors/src/MCTrackerHitProcessor.cxx +++ b/processors/src/MCTrackerHitProcessor.cxx @@ -54,6 +54,9 @@ bool MCTrackerHitProcessor::process(IEvent* ievent) { // Set the energy deposit of the hit mc_tracker_hit->setEdep(lcio_mcTracker_hit->getEDep()); + // Set the pdg of particle generating the hit + mc_tracker_hit->setPDG(lcio_mcTracker_hit->getMCParticle()->getPDG()); + // Set the time of the hit mc_tracker_hit->setTime(lcio_mcTracker_hit->getTime()); diff --git a/processors/src/SvtRawDataProcessor.cxx b/processors/src/SvtRawDataProcessor.cxx index d28e08717..8640fed0c 100644 --- a/processors/src/SvtRawDataProcessor.cxx +++ b/processors/src/SvtRawDataProcessor.cxx @@ -14,7 +14,7 @@ SvtRawDataProcessor::~SvtRawDataProcessor() { void SvtRawDataProcessor::initialize(TTree* tree) { - rawhits_ = new TClonesArray(Collections::RAW_SVT_HITS, 100000); + rawhits_ = new TClonesArray("RawSvtHit", 100000); tree->Branch(Collections::RAW_SVT_HITS,&rawhits_); } From 2b5876e0fb5fd62c6ae76c77e0b46708b5747d05 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 24 Oct 2019 11:32:44 -0700 Subject: [PATCH 153/314] Change how processors handle the output file slightly --- processing/include/HpsEventFile.h | 1 + processing/include/Processor.h | 14 ++++++++++++-- processing/src/Process.cxx | 1 + processors/include/ClusterOnTrackAnaProcessor.h | 1 - processors/include/MCAnaProcessor.h | 1 - processors/src/ClusterOnTrackAnaProcessor.cxx | 1 - processors/src/MCAnaProcessor.cxx | 2 -- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/processing/include/HpsEventFile.h b/processing/include/HpsEventFile.h index 77b1c0a2b..381bb257e 100644 --- a/processing/include/HpsEventFile.h +++ b/processing/include/HpsEventFile.h @@ -17,6 +17,7 @@ class HpsEventFile : public IEventFile { virtual bool nextEvent(); void setupEvent(IEvent* ievent); void resetOutputFileDir() { ofile_->cd();} + TFile* getOutputFile() { return ofile_;} void close(); diff --git a/processing/include/Processor.h b/processing/include/Processor.h index cfc5af244..c56a00d87 100644 --- a/processing/include/Processor.h +++ b/processing/include/Processor.h @@ -21,6 +21,7 @@ class Process; class Processor; class TTree; +class TFile; class IEvent; /** Typedef for ProcessorFactory use. */ @@ -66,6 +67,12 @@ class Processor { */ virtual void initialize(TTree* tree) = 0; + /** + * Set output TFile for AnaProcessors + * @param pointer to output TFile + */ + virtual void setFile(TFile* outFile) {outF_ = outFile;}; + /** * Process the event and put new data products into it. * @param event The Event to process. @@ -91,12 +98,15 @@ class Processor { /** Handle to the Process. */ Process& process_; - + + /** output file pointer */ + TFile* outF_{nullptr}; + private: /** The name of the Processor. */ std::string name_; - + }; diff --git a/processing/src/Process.cxx b/processing/src/Process.cxx index 41bac3cb5..14c13f815 100644 --- a/processing/src/Process.cxx +++ b/processing/src/Process.cxx @@ -33,6 +33,7 @@ void Process::runOnRoot() { } for (auto module : sequence_) { module->initialize(event.getTree()); + module->setFile(file->getOutputFile()); } while (file->nextEvent() && (event_limit_ < 0 || (n_events_processed < event_limit_))) { if (n_events_processed%1000 == 0) diff --git a/processors/include/ClusterOnTrackAnaProcessor.h b/processors/include/ClusterOnTrackAnaProcessor.h index e13866748..b52528dfc 100644 --- a/processors/include/ClusterOnTrackAnaProcessor.h +++ b/processors/include/ClusterOnTrackAnaProcessor.h @@ -51,7 +51,6 @@ class ClusterOnTrackAnaProcessor : public Processor { TBranch* btracks_{nullptr}; std::vector hits_{}; TBranch* bhits_{nullptr}; - TFile* outF_{nullptr}; }; diff --git a/processors/include/MCAnaProcessor.h b/processors/include/MCAnaProcessor.h index 6c78c6b6c..60baec311 100644 --- a/processors/include/MCAnaProcessor.h +++ b/processors/include/MCAnaProcessor.h @@ -48,7 +48,6 @@ class MCAnaProcessor : public Processor { TClonesArray* mcParts_{nullptr}; TClonesArray* mcTrkrHits_{nullptr}; TClonesArray* mcEcalHits_{nullptr}; - TFile* outF_{nullptr}; }; diff --git a/processors/src/ClusterOnTrackAnaProcessor.cxx b/processors/src/ClusterOnTrackAnaProcessor.cxx index 20e7081e5..c1d3e6da8 100644 --- a/processors/src/ClusterOnTrackAnaProcessor.cxx +++ b/processors/src/ClusterOnTrackAnaProcessor.cxx @@ -54,7 +54,6 @@ bool ClusterOnTrackAnaProcessor::process(IEvent* ievent) { void ClusterOnTrackAnaProcessor::finalize() { clusterHistos->saveHistos(outF_,""); - //outF_->Close(); delete clusterHistos; clusterHistos = nullptr; } diff --git a/processors/src/MCAnaProcessor.cxx b/processors/src/MCAnaProcessor.cxx index 3de4a7f1a..f0237ceea 100644 --- a/processors/src/MCAnaProcessor.cxx +++ b/processors/src/MCAnaProcessor.cxx @@ -46,9 +46,7 @@ bool MCAnaProcessor::process(IEvent* ievent) { void MCAnaProcessor::finalize() { - outF_ = new TFile("testMCAnaHistos.root","RECREATE"); histos->saveHistos(outF_,""); - outF_->Close(); delete histos; histos = nullptr; } From f3d6f100308e584a531215df048ef79655e33921 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Thu, 24 Oct 2019 12:55:19 -0700 Subject: [PATCH 154/314] Move cut flow histogram to Process.cxx --- analysis/include/HistoManager.h | 4 ---- analysis/src/HistoManager.cxx | 3 --- processing/src/Process.cxx | 19 +++++++++++++++++-- processors/src/MCAnaProcessor.cxx | 3 +-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/analysis/include/HistoManager.h b/analysis/include/HistoManager.h index 50901e3b6..39ec4532a 100644 --- a/analysis/include/HistoManager.h +++ b/analysis/include/HistoManager.h @@ -67,8 +67,6 @@ class HistoManager { virtual void Define2DHistos(){}; virtual void Define1DHistos(){}; - virtual void FillEvent(){event_h->Fill(0.0);}; - virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder = ""); virtual void saveHistos(TFile* outF = nullptr,std::string folder = ""); @@ -92,8 +90,6 @@ class HistoManager { std::map histos3d; typedef std::map::iterator it3d; - TH1D * event_h; - bool debug_{false}; }; diff --git a/analysis/src/HistoManager.cxx b/analysis/src/HistoManager.cxx index 881d12a74..8f3a76324 100644 --- a/analysis/src/HistoManager.cxx +++ b/analysis/src/HistoManager.cxx @@ -9,7 +9,6 @@ HistoManager::HistoManager() { HistoManager::HistoManager(const std::string& inputName) { m_name = inputName; - event_h = new TH1D("event_h","Number of Events Processed;;Events", 21, -10.5, 10.5); } HistoManager::~HistoManager() { @@ -212,8 +211,6 @@ void HistoManager::saveHistos(TFile* outF,std::string folder) { dir->cd(); } - event_h->Write(); - for (it3d it = histos3d.begin(); it!=histos3d.end(); ++it) { if (!it->second){ std::cout<first<<" Null ptr in saving.."<process(&event); } //event.Clear(); + event_h->Fill(0.0); ++n_events_processed; } //Pass to next file @@ -52,6 +57,7 @@ void Process::runOnRoot() { //Select the output file for storing the results of the processors. file->resetOutputFileDir(); + event_h->Write(); for (auto module : sequence_) { //TODO:Change the finalize method module->finalize(); @@ -61,6 +67,8 @@ void Process::runOnRoot() { file->close(); delete file; file = nullptr; + delete event_h; + event_h = nullptr; } } } catch (std::exception& e) { @@ -73,6 +81,7 @@ void Process::run() { try { int n_events_processed = 0; + TH1D * event_h = new TH1D("event_h","Number of Events Processed;;Events", 21, -10.5, 10.5); if (input_files_.empty()) throw std::runtime_error("Please specify files to process."); @@ -95,9 +104,9 @@ void Process::run() { file = new EventFile(ifile, output_files_[cfile]); file->setupEvent(&event); } - + TTree* tree = new TTree("HPS_Event","HPS event tree"); - event.setTree(tree); + event.setTree(tree); // first, notify everyone that we are starting for (auto module : sequence_) { module->initialize(tree); @@ -117,9 +126,13 @@ void Process::run() { break; } ++n_events_processed; + event_h->Fill(0.0); } ++cfile; + //Prepare to write to file + file->resetOutputFileDir(); + event_h->Write(); // Finalize all modules. for (auto module : sequence_) { module->finalize(); @@ -129,6 +142,8 @@ void Process::run() { file->close(); delete file; file = nullptr; + delete event_h; + event_h = nullptr; } } diff --git a/processors/src/MCAnaProcessor.cxx b/processors/src/MCAnaProcessor.cxx index f0237ceea..3be022eba 100644 --- a/processors/src/MCAnaProcessor.cxx +++ b/processors/src/MCAnaProcessor.cxx @@ -20,7 +20,7 @@ void MCAnaProcessor::initialize(TTree* tree) { // init histos histos = new MCAnaHistos("hitOnTrack_2D"); histos->Define1DHistos(); - histos->Define2DHistos(); + //histos->Define2DHistos(); // init TClonesArrays mcParts_ = new TClonesArray("MCParticle" , 1000000); @@ -36,7 +36,6 @@ void MCAnaProcessor::initialize(TTree* tree) { bool MCAnaProcessor::process(IEvent* ievent) { - histos->FillEvent(); histos->FillMCParticles(mcParts_); histos->FillMCTrackerHits(mcTrkrHits_); histos->FillMCEcalHits(mcEcalHits_); From 5a566497ef03a2bf068890df93c0284b5ceacd53 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 28 Oct 2019 11:35:50 -0700 Subject: [PATCH 155/314] Add script to draw MC comparison plots --- analysis/src/MCAnaHistos.cxx | 16 +++++++++-- pyplot/compareMC.py | 47 ++++++++++++++++++++++++++++++++ pyplot/utilities.py | 52 +++++++++++++++--------------------- 3 files changed, 82 insertions(+), 33 deletions(-) create mode 100755 pyplot/compareMC.py diff --git a/analysis/src/MCAnaHistos.cxx b/analysis/src/MCAnaHistos.cxx index b9e0feca1..4b1f3449f 100644 --- a/analysis/src/MCAnaHistos.cxx +++ b/analysis/src/MCAnaHistos.cxx @@ -10,8 +10,12 @@ void MCAnaHistos::Define1DHistos() { 450, 0, 4.5); histos1d["MCpartsEnergyLow_h"] = new TH1F("MCpartsEnergyLow_h", ";Energy of Sim Particle [MeV];Sim Particles / 1 MeV", 200, 0, 200); + histos1d["numMuons_h"] = new TH1F("numMuons_h", ";Number of Sim Muons;Events", + 10, -0.5, 9.5); histos1d["minMuonE_h"] = new TH1F("minMuonE_h", "Minimum MC Muon Energy;Energy [GeV];Sim Particles / 10 MeV", 450, 0, 4.5); + histos1d["minMuonEhigh_h"] = new TH1F("minMuonEhigh_h","Minimum MC Muon Energy;Energy [GeV];Sim Particles/100 keV", + 3000, 2.2, 2.5); // init MCTrackerHit Histos histos1d["numMCTrkrHit_h"] = new TH1F("numMCTrkrHit_h", ";Number of Sim Tracker Hits;Events", @@ -26,25 +30,33 @@ void MCAnaHistos::Define1DHistos() { 60, -0.5, 59.5); histos1d["mcEcalHitEnergy_h"] = new TH1F("mcEcalHitEnergy_h", ";Ecal Hit Energy [MeV];Sim Particles / 2 MeV", 200, 0, 400); + sumw2(); } void MCAnaHistos::FillMCParticles(TClonesArray* mcParts, float weight ) { int nParts = mcParts->GetEntriesFast(); histos1d["numMCparts_h"]->Fill((float)nParts, weight); + int nMuons = 0; double minMuonE = -99.9; for (int i=0; i < nParts; i++) { MCParticle *part = (MCParticle*)mcParts->At(i); int pdg = part->getPDG(); double energy = part->getEnergy(); - if ((fabs(pdg) == 13) && (energy < minMuonE || minMuonE < 0.0)) + if (fabs(pdg) == 13) { - minMuonE = energy; + nMuons++; + if(energy < minMuonE || minMuonE < 0.0) + { + minMuonE = energy; + } } histos1d["MCpartsEnergy_h"]->Fill(energy, weight); histos1d["MCpartsEnergyLow_h"]->Fill(energy*1000.0, weight);// Scaled to MeV } + histos1d["numMuons_h"]->Fill(nMuons, weight); histos1d["minMuonE_h"]->Fill(minMuonE, weight); + histos1d["minMuonEhigh_h"]->Fill(minMuonE, weight); } void MCAnaHistos::FillMCTrackerHits(TClonesArray* mcTrkrHits, float weight ) { diff --git a/pyplot/compareMC.py b/pyplot/compareMC.py new file mode 100755 index 000000000..558f325e7 --- /dev/null +++ b/pyplot/compareMC.py @@ -0,0 +1,47 @@ +import ROOT as r +import os +import utilities as utils + + +utils.SetStyle() + +path = "/home/bravo/hps3/users/bravo/sim/det16/singleMuon/" +inFileList = [ + "slic/slicSingleMu4deg_anaMC.root", + "hps-sim/muonHpsSim_anaMC.root"] + + + +colors = [r.kBlack, r.kRed, r.kBlue, r.kGreen+2, r.kOrange-2] + +inputFiles = [] +legends = ["slic","hps-sim"] +outdir = "./" + +if not os.path.exists(outdir): + os.makedirs(outdir) + +r.gROOT.SetBatch(1) + +for ifile in inFileList: + inf = r.TFile(path+"/"+ifile) + inputFiles.append(inf) + pass + +canvs = [] +for key in inputFiles[0].GetListOfKeys(): + histos = [] + print key.GetName() + c = r.TCanvas() + for i_f in range(0,len(inputFiles)): + histos.append(inputFiles[i_f].Get(key.GetName())) + histos[i_f].SetMarkerColor(colors[i_f]) + histos[i_f].SetLineColor(colors[i_f]) + pass + canvs.append(utils.MakePlot(key.GetName(),outdir,histos,legends,".png",LogY=True)) + pass + +outF = r.TFile("slicSingleMu_compMC.root","RECREATE") +outF.cd() +for canv in canvs: canv.Write() +outF.Close() diff --git a/pyplot/utilities.py b/pyplot/utilities.py index 3a5e9bec9..0b2d76c33 100755 --- a/pyplot/utilities.py +++ b/pyplot/utilities.py @@ -1,5 +1,6 @@ from ROOT import * from array import array +from copy import deepcopy import os,sys colors = [kBlack,kBlue+2,kRed+2,kGreen-1,kYellow+2,kRed+2,kAzure-2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3,kYellow+2,kRed+2,kBlue+2,kGreen-8,kOrange+3] @@ -214,7 +215,7 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, Xmin=0 Xmax=1 - can = TCanvas() + can = TCanvas(name, name, 1200, 800) can.SetMargin(0,0,0,0) top = TPad("top","top",0,0.42,1,1) if LogX: @@ -222,11 +223,9 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, bot.SetLogx(1) if LogY: top.SetLogy(1) - bot = TPad("bot","bot",0,0,1,0.38) - #----------Histogram------------# top.Draw() @@ -239,9 +238,6 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, plotsProperties=[] for ih in xrange(len(histos)): - - - if (Normalise): histos[ih].Scale(1./histos[ih].Integral()) @@ -251,6 +247,8 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, histos[ih].SetMarkerColor(colors[ih]) histos[ih].SetMarkerStyle(markers[ih]) histos[ih].SetLineColor(colors[ih]) + histos[ih].GetXaxis().CenterTitle() + histos[ih].GetYaxis().CenterTitle() plotsProperties.append(("#mu=%.4f"%round(histos[ih].GetMean(),4))+(" #sigma=%.4f"%round(histos[ih].GetRMS(),4))) @@ -259,32 +257,28 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, histos[ih].Rebin(RebinFactor) if ih==0: - histos[ih].GetYaxis().SetRangeUser(ymin,ymax) + #histos[ih].GetYaxis().SetRangeUser(ymin,ymax) if noErrors: #histos[ih].GetXaxis().SetTextSize(0.045) #histos[ih].GetYaxis().SetTextSize(0.045) - - - histos[ih].Draw("hist p") - + histos[ih].Draw("pe") else: - histos[ih].Draw() + histos[ih].Draw("pe") if xtitle: histos[ih].GetXaxis().SetTitle(xtitle) if ytitle: histos[ih].GetYaxis().SetTitle(ytitle) else: if noErrors: - histos[ih].Draw("same hist p") + histos[ih].Draw("same hist") else: - histos[ih].Draw("same") + histos[ih].Draw("same hist") - InsertText(runNumber,additionalText,0.85) + InsertText(runNumber,additionalText,0.8,xoffset=0.75) if (WriteMean): - InsertText("",plotsProperties,0.85,0.6,False) - + InsertText("",plotsProperties,0.8,0.6,False) if len(legends)>0: #print "building legend" @@ -293,35 +287,31 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, linesep = 0.07 lowerY=upperY - len(legends)* linesep #minX = 0.51 - minX = 0.18 - maxX = minX+0.26 + minX = 0.75 + maxX = minX+0.15 leg=TLegend(minX,upperY,maxX,lowerY) leg.SetBorderSize(0) leg.SetFillColor(0) leg.SetTextSize(0.04) - - - for i_leg in xrange(len(legends)): #print "Adding Entry",i_leg, legends[i_leg] leg.AddEntry(histos[i_leg],legends[i_leg],"lpf") - + pass leg.Draw() - - + pass #-------------Ratio---------------------# - bot.cd() reference = histos[0].Clone("reference") reference.GetYaxis().SetTitle("Ratio") reference.GetYaxis().SetTitleSize(0.06) + reference.GetXaxis().SetTitleSize(0.1) + reference.GetXaxis().SetLabelSize(0.12) reference.GetYaxis().SetRangeUser(RatioMin,RatioMax) reference.GetYaxis().SetNdivisions(508) reference.GetYaxis().SetDecimals(True) reference.Draw("axis") - if (RatioType=="Sequential"): @@ -354,7 +344,7 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, numerator.SetMaximum(100.) numerator.Divide(histos[ih-1]) - numerator.DrawCopy("hist p same") + numerator.DrawCopy("pe same") elif (RatioType=="Alternate2"): @@ -373,9 +363,9 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, line = TLine() line.SetLineStyle(kDashed) line.DrawLine(reference.GetXaxis().GetXmin(),1,reference.GetXaxis().GetXmax(),1) - can.SaveAs(outdir+"/"+name+oFext) + return deepcopy(can) def DivideHistos(h1,h2): @@ -394,7 +384,7 @@ def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle os.mkdir(outdir) - can = TCanvas() + can = TCanvas(name,name,1500,1000) if LogY: can.SetLogy(1) @@ -436,7 +426,7 @@ def Make1Dplots(name,outdir,histos,colors,markers,legends,oFext,xtitle="",ytitle else: histos[ih].Draw("same") - InsertText(runNumber,additionalText,0.85,xoffset=0.7) + InsertText(runNumber,additionalText,0.8,xoffset=0.7) if len(legends)>0: #print "building legend" From 847dd4805ef564e36d411038e58ca74bafafc71e Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 28 Oct 2019 18:40:19 -0700 Subject: [PATCH 156/314] Change some processors to use vectors instead of TClonesArrays --- event/include/EventLinkDef.h | 4 + processors/include/ECalDataProcessor.h | 8 +- processors/include/SvtDataProcessor.h | 10 +- processors/include/TrackingProcessor.h | 6 +- processors/src/ECalDataProcessor.cxx | 19 +- processors/src/SvtDataProcessor.cxx | 22 +- processors/src/utilities.cxx | 588 ++++++++++++------------- 7 files changed, 332 insertions(+), 325 deletions(-) diff --git a/event/include/EventLinkDef.h b/event/include/EventLinkDef.h index 7376f19bc..b8b6b0489 100644 --- a/event/include/EventLinkDef.h +++ b/event/include/EventLinkDef.h @@ -43,6 +43,10 @@ #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; +#pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; #pragma link C++ class vector +; diff --git a/processors/include/ECalDataProcessor.h b/processors/include/ECalDataProcessor.h index 81bf5b4f9..d1811d901 100644 --- a/processors/include/ECalDataProcessor.h +++ b/processors/include/ECalDataProcessor.h @@ -82,16 +82,16 @@ class ECalDataProcessor : public Processor { * @param hit The CalorimeterHit whose ID will be used to unpack the * the field value. */ - UTIL::BitFieldValue getIdentifierFieldValue(std::string field, EVENT::CalorimeterHit* hit); + UTIL::BitFieldValue getIdentifierFieldValue(std::string field, EVENT::CalorimeterHit* hit); /** TClonesArray collection containing all ECal hits. */ - TClonesArray* cal_hits_{nullptr}; + std::vector cal_hits_; /** TClonesArray collection containing all ECal clusters. */ - TClonesArray* clusters_{nullptr}; + std::vector clusters_; /** Encoding string describing cell ID. */ - const std::string encoder_string_{"system:6,layer:2,ix:-8,iy:-6"}; + const std::string encoder_string_{"system:6,layer:2,ix:-8,iy:-6"}; }; // ECalDataProcessor diff --git a/processors/include/SvtDataProcessor.h b/processors/include/SvtDataProcessor.h index 6d90b0c74..bbe36872d 100644 --- a/processors/include/SvtDataProcessor.h +++ b/processors/include/SvtDataProcessor.h @@ -10,6 +10,7 @@ //-----------------// #include #include +#include //----------// // LCIO // @@ -22,11 +23,6 @@ #include #include -//----------// -// ROOT // -//----------// -#include "TClonesArray.h" - //-----------// // hpstr // //-----------// @@ -76,10 +72,10 @@ class SvtDataProcessor : public Processor { private: /** Container to hold all TrackerHit objects. */ - TClonesArray* hits_{nullptr}; + std::vector hits_; /** Container to hold all Track objects. */ - TClonesArray* tracks_{nullptr}; + std::vector tracks_; }; // SvtDataProcessor diff --git a/processors/include/TrackingProcessor.h b/processors/include/TrackingProcessor.h index 5b5525ef3..731cd8512 100644 --- a/processors/include/TrackingProcessor.h +++ b/processors/include/TrackingProcessor.h @@ -79,17 +79,17 @@ class TrackingProcessor : public Processor { private: /** Container to hold all TrackerHit objects. */ - std::vector hits_{}; + std::vector hits_{}; /** Container to hold all Track objects. */ - std::vector tracks_{}; + std::vector tracks_{}; /** Container to hold all raw hits objecs. */ std::vector rawhits_{}; bool _debug{false}; - + }; // Tracking Processor diff --git a/processors/src/ECalDataProcessor.cxx b/processors/src/ECalDataProcessor.cxx index 6cf8cd159..c7acbd0a9 100644 --- a/processors/src/ECalDataProcessor.cxx +++ b/processors/src/ECalDataProcessor.cxx @@ -15,13 +15,16 @@ ECalDataProcessor::~ECalDataProcessor() { } void ECalDataProcessor::initialize(TTree* tree) { - - cal_hits_ = new TClonesArray("CalHit", 100000); - clusters_ = new TClonesArray("CalCluster", 1000000); + tree->Branch(Collections::ECAL_HITS, &cal_hits_); + tree->Branch(Collections::ECAL_CLUSTERS, &clusters_); } bool ECalDataProcessor::process(IEvent* ievent) { + for(int i = 0; i < cal_hits_.size(); i++) delete cal_hits_.at(i); + for(int i = 0; i < clusters_.size(); i++) delete clusters_.at(i); + cal_hits_.clear(); + clusters_.clear(); // Attempt to retrieve the collection "TimeCorrEcalHits" from the event. If // the collection doesn't exist, handle the DataNotAvailableCollection and // attempt to retrieve the collection "EcalCalHits". If that collection @@ -58,7 +61,7 @@ bool ECalDataProcessor::process(IEvent* ievent) { // 0.1 ns resolution is sufficient to distinguish any 2 hits on the same crystal. int id1 = static_cast(10.0*lc_hit->getTime()); - CalHit* cal_hit = static_cast(cal_hits_->ConstructedAt(ihit)); + CalHit* cal_hit = new CalHit(); // Store the hit in the map for easy access later. hit_map[ std::make_pair(id0,id1) ] = cal_hit; @@ -74,11 +77,10 @@ bool ECalDataProcessor::process(IEvent* ievent) { int index_y = this->getIdentifierFieldValue("iy", lc_hit); cal_hit->setCrystalIndices(index_x, index_y); + cal_hits_.push_back(cal_hit); } - event->addCollection(hits_coll_name, cal_hits_); - // Get the collection of Ecal clusters from the event EVENT::LCCollection* clusters = static_cast(event->getLCCollection(Collections::ECAL_CLUSTERS)); @@ -90,7 +92,7 @@ bool ECalDataProcessor::process(IEvent* ievent) { IMPL::ClusterImpl* lc_cluster = static_cast(clusters->getElementAt(icluster)); // Add a cluster to the event - CalCluster* cluster = static_cast(clusters_->ConstructedAt(icluster)); + CalCluster* cluster = new CalCluster(); // Set the cluster position cluster->setPosition(lc_cluster->getPosition()); @@ -135,10 +137,9 @@ bool ECalDataProcessor::process(IEvent* ievent) { // Set the cluster seed. cluster->setSeed(seed_hit); + clusters_.push_back(cluster); } - event->addCollection(Collections::ECAL_CLUSTERS, clusters_); - return true; } diff --git a/processors/src/SvtDataProcessor.cxx b/processors/src/SvtDataProcessor.cxx index 4f494773f..440af2b6e 100644 --- a/processors/src/SvtDataProcessor.cxx +++ b/processors/src/SvtDataProcessor.cxx @@ -9,13 +9,17 @@ SvtDataProcessor::~SvtDataProcessor() { } void SvtDataProcessor::initialize(TTree* tree) { - - tracks_ = new TClonesArray("Track", 100000); - hits_ = new TClonesArray("TrackerHit", 100000); + // Add branches to tree + tree->Branch(Collections::GBL_TRACKS, &tracks_); + tree->Branch(Collections::TRACKER_HITS, &hits_); } bool SvtDataProcessor::process(IEvent* ievent) { + for(int i = 0; i < tracks_.size(); i++) delete tracks_.at(i); + for(int i = 0; i < hits_.size(); i++) delete hits_.at(i); + tracks_.clear(); + hits_.clear(); Event* event = static_cast (ievent); @@ -36,7 +40,7 @@ bool SvtDataProcessor::process(IEvent* ievent) { IMPL::TrackerHitImpl* lc_tracker_hit = static_cast(tracker_hits->getElementAt(ihit)); // Add a tracker hit to the event - TrackerHit* tracker_hit = static_cast(hits_->ConstructedAt(ihit)); + TrackerHit* tracker_hit = new TrackerHit(); // Rotate the position of the LCIO TrackerHit and set the position of // the TrackerHit @@ -59,11 +63,12 @@ bool SvtDataProcessor::process(IEvent* ievent) { // Map the TrackerHit object to the corresponding SvtHit object. This // will be used later when setting references for hits on tracks. hit_map[lc_tracker_hit] = tracker_hit; + hits_.push_back(tracker_hit); } // Add the hit collection to the event - event->addCollection(Collections::TRACKER_HITS, hits_); + //event->addCollection(Collections::TRACKER_HITS, hits_); // Get all track collections from the event EVENT::LCCollection* tracks = event->getLCCollection(Collections::GBL_TRACKS); @@ -76,7 +81,7 @@ bool SvtDataProcessor::process(IEvent* ievent) { EVENT::Track* lc_track = static_cast(tracks->getElementAt(itrack)); // Add a track to the event - Track* track = static_cast(tracks_->ConstructedAt(itrack)); + Track* track = new Track(); // Set the track parameters track->setTrackParameters(lc_track->getD0(), @@ -158,7 +163,7 @@ bool SvtDataProcessor::process(IEvent* ievent) { // Check that the TrackData data structure is correct. If it's // not, throw a runtime exception. - if (track_datum->getNDouble() != 14 || track_datum->getNFloat() != 1 + if (track_datum->getNDouble() < 12 || track_datum->getNFloat() != 1 || track_datum->getNInt() != 1) { throw std::runtime_error("[ SvtDataProcessor ]: The collection " + std::string(Collections::TRACK_DATA) @@ -190,9 +195,10 @@ bool SvtDataProcessor::process(IEvent* ievent) { // Add a reference to the hit track->addHit(hit_map[hit]); } + tracks_.push_back(track); } - event->addCollection(Collections::GBL_TRACKS, tracks_); + //event->addCollection(Collections::GBL_TRACKS, tracks_); return true; } diff --git a/processors/src/utilities.cxx b/processors/src/utilities.cxx index 1c1125e94..da178ba51 100644 --- a/processors/src/utilities.cxx +++ b/processors/src/utilities.cxx @@ -1,335 +1,335 @@ #include "utilities.h" #include /* -void utils::buildTrackCollection(std::vector& tracks, - Event* event, - const char* LCTrackCollection) -{ - - EVENT::LCCollection* lc_tracks event->getLCCollection(LCTrackCollection); - - -} + void utils::buildTrackCollection(std::vector& tracks, + Event* event, + const char* LCTrackCollection) + { + + EVENT::LCCollection* lc_tracks event->getLCCollection(LCTrackCollection); + + + } */ bool utils::hasCollection(EVENT::LCEvent* lc_event,const std::string& collection) { - - if (!lc_event || collection.empty()) + + if (!lc_event || collection.empty()) + return false; + + auto evColls = lc_event->getCollectionNames(); + auto it = std::find(evColls->begin(),evColls->end(), collection); + if (it!=evColls->end()) + return true; return false; - - auto evColls = lc_event->getCollectionNames(); - auto it = std::find(evColls->begin(),evColls->end(), collection); - if (it!=evColls->end()) - return true; - return false; } Vertex* utils::buildVertex(EVENT::Vertex* lc_vertex) { - - if (!lc_vertex) - return nullptr; - - //TODO move the static cast outside? - - Vertex* vertex = new Vertex(); - vertex->setChi2 (lc_vertex->getChi2()); - vertex->setProbability (lc_vertex->getProbability()); - vertex->setID (lc_vertex->id()); - vertex->setType (lc_vertex->getAlgorithmType()); - vertex->setVtxParameters((std::vector)lc_vertex->getParameters()); - - //TODO Rotate the covariance matrix! - vertex->setCovariance ((std::vector)lc_vertex->getCovMatrix()); - //std::cout<getVertexParameterNames[0]<setType (lc_vertex->getAlgorithmType()); - - vertex->setPos (lc_vertex->getPosition(),false); - - - return vertex; + + if (!lc_vertex) + return nullptr; + + //TODO move the static cast outside? + + Vertex* vertex = new Vertex(); + vertex->setChi2 (lc_vertex->getChi2()); + vertex->setProbability (lc_vertex->getProbability()); + vertex->setID (lc_vertex->id()); + vertex->setType (lc_vertex->getAlgorithmType()); + vertex->setVtxParameters((std::vector)lc_vertex->getParameters()); + + //TODO Rotate the covariance matrix! + vertex->setCovariance ((std::vector)lc_vertex->getCovMatrix()); + //std::cout<getVertexParameterNames[0]<setType (lc_vertex->getAlgorithmType()); + + vertex->setPos (lc_vertex->getPosition(),false); + + + return vertex; } Track* utils::buildTrack(EVENT::Track* lc_track, - EVENT::LCCollection* gbl_kink_data, - EVENT::LCCollection* track_data) { - - if (!lc_track) - return nullptr; - - Track* track = new Track(); - // Set the track parameters - track->setTrackParameters(lc_track->getD0(), - lc_track->getPhi(), - lc_track->getOmega(), - lc_track->getTanLambda(), - lc_track->getZ0()); - - // Set the track type - track->setType(lc_track->getType()); - - // Set the track fit chi^2 - track->setChi2(lc_track->getChi2()); - - // Set the track ndf - track->setNdf(lc_track->getNdf()); - - // Set the position of the extrapolated track at the ECal face. The - // extrapolation uses the full 3D field map. - const EVENT::TrackState* track_state - = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); - - if (track_state) { - double position_at_ecal[3] = { - track_state->getReferencePoint()[1], - track_state->getReferencePoint()[2], - track_state->getReferencePoint()[0] - }; - track->setPositionAtEcal(position_at_ecal); - } - - if (gbl_kink_data) { - // Instantiate an LCRelation navigator which will allow faster access - // to GBLKinkData object - UTIL::LCRelationNavigator* gbl_kink_data_nav - = new UTIL::LCRelationNavigator(gbl_kink_data); - - // Get the list of GBLKinkData associated with the LCIO Track - EVENT::LCObjectVec gbl_kink_data_list - = gbl_kink_data_nav->getRelatedFromObjects(lc_track); - - // The container of GBLKinkData objects should only contain a - // single object. If not, throw an exception - if (gbl_kink_data_list.size() != 1) { - throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA_REL) - + " has the wrong data structure."); - } - - // Get the list GBLKinkData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* gbl_kink_datum - = static_cast(gbl_kink_data_list.at(0)); - - // Set the lambda and phi kink values - for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { - track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); - track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); - } - - delete gbl_kink_data_nav; - - } // add gbl kink data - - if (track_data) { - - // Instantiate an LCRelation navigator which will allow faster access - // to TrackData objects - UTIL::LCRelationNavigator* track_data_nav - = new UTIL::LCRelationNavigator(track_data); - - // Get the list of TrackData associated with the LCIO Track - EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); - - // The container of TrackData objects should only contain a single - // object. If not, throw an exception. - if (track_data_list.size() == 1) { - - // Get the TrackData GenericObject associated with the LCIO Track - IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); - - // Check that the TrackData data structure is correct. If it's - // not, throw a runtime exception. - if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 - || track_datum->getNInt() != 1) { - throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA) - + " has the wrong structure."); - } - - // Set the SvtTrack isolation values - for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { - track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); - } - - // Set the SvtTrack time - track->setTrackTime(track_datum->getFloatVal(0)); - - // Set the volume (top/bottom) in which the SvtTrack resides - track->setTrackVolume(track_datum->getIntVal(0)); + EVENT::LCCollection* gbl_kink_data, + EVENT::LCCollection* track_data) { + + if (!lc_track) + return nullptr; + + Track* track = new Track(); + // Set the track parameters + track->setTrackParameters(lc_track->getD0(), + lc_track->getPhi(), + lc_track->getOmega(), + lc_track->getTanLambda(), + lc_track->getZ0()); + + // Set the track type + track->setType(lc_track->getType()); + + // Set the track fit chi^2 + track->setChi2(lc_track->getChi2()); + + // Set the track ndf + track->setNdf(lc_track->getNdf()); + + // Set the position of the extrapolated track at the ECal face. The + // extrapolation uses the full 3D field map. + const EVENT::TrackState* track_state + = lc_track->getTrackState(EVENT::TrackState::AtCalorimeter); + + if (track_state) { + double position_at_ecal[3] = { + track_state->getReferencePoint()[1], + track_state->getReferencePoint()[2], + track_state->getReferencePoint()[0] + }; + track->setPositionAtEcal(position_at_ecal); } - delete track_data_nav; - - } //add track data - + + if (gbl_kink_data) { + // Instantiate an LCRelation navigator which will allow faster access + // to GBLKinkData object + UTIL::LCRelationNavigator* gbl_kink_data_nav + = new UTIL::LCRelationNavigator(gbl_kink_data); + + // Get the list of GBLKinkData associated with the LCIO Track + EVENT::LCObjectVec gbl_kink_data_list + = gbl_kink_data_nav->getRelatedFromObjects(lc_track); + + // The container of GBLKinkData objects should only contain a + // single object. If not, throw an exception + if (gbl_kink_data_list.size() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA_REL) + + " has the wrong data structure."); + } + + // Get the list GBLKinkData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* gbl_kink_datum + = static_cast(gbl_kink_data_list.at(0)); + + // Set the lambda and phi kink values + for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { + track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); + track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); + } + + delete gbl_kink_data_nav; + + } // add gbl kink data + + if (track_data) { + + // Instantiate an LCRelation navigator which will allow faster access + // to TrackData objects + UTIL::LCRelationNavigator* track_data_nav + = new UTIL::LCRelationNavigator(track_data); + + // Get the list of TrackData associated with the LCIO Track + EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); + + // The container of TrackData objects should only contain a single + // object. If not, throw an exception. + if (track_data_list.size() == 1) { + + // Get the TrackData GenericObject associated with the LCIO Track + IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); + + // Check that the TrackData data structure is correct. If it's + // not, throw a runtime exception. + if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 + || track_datum->getNInt() != 1) { + throw std::runtime_error("[ TrackingProcessor ]: The collection " + + std::string(Collections::TRACK_DATA) + + " has the wrong structure."); + } + + // Set the SvtTrack isolation values + for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { + track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); + } + + // Set the SvtTrack time + track->setTrackTime(track_datum->getFloatVal(0)); + + // Set the volume (top/bottom) in which the SvtTrack resides + track->setTrackVolume(track_datum->getIntVal(0)); + } + delete track_data_nav; + + } //add track data + return track; } RawSvtHit* utils::buildRawHit(EVENT::TrackerRawData* rawTracker_hit, - EVENT::LCCollection* raw_svt_hit_fits) { - - EVENT::long64 value = - EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) | - ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 ); - decoder.setValue(value); - - RawSvtHit* rawHit = new RawSvtHit(); - rawHit->setSystem(decoder["system"]); - rawHit->setBarrel(decoder["barrel"]); - rawHit->setLayer(decoder["layer"]); - rawHit->setModule(decoder["module"]); - rawHit->setSensor(decoder["sensor"]); - rawHit->setSide(decoder["side"]); - rawHit->setStrip(decoder["strip"]); - - // Extract ADC values for this hit - int hit_adcs[6] = { - (int)rawTracker_hit->getADCValues().at(0), - (int)rawTracker_hit->getADCValues().at(1), - (int)rawTracker_hit->getADCValues().at(2), - (int)rawTracker_hit->getADCValues().at(3), - (int)rawTracker_hit->getADCValues().at(4), - (int)rawTracker_hit->getADCValues().at(5)}; - - rawHit->setADCs(hit_adcs); - if (raw_svt_hit_fits) { - UTIL::LCRelationNavigator* rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); - - // Get the list of fit params associated with the raw tracker hit - EVENT::LCObjectVec rawTracker_hit_fits_list - = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); - - // Get the list SVTFittedRawTrackerHit GenericObject associated with the SVTRawTrackerHit - IMPL::LCGenericObjectImpl* hit_fit_param - = static_cast(rawTracker_hit_fits_list.at(0)); - - double fit_params[5] = { - (double)hit_fit_param->getDoubleVal(0), - (double)hit_fit_param->getDoubleVal(1), - (double)hit_fit_param->getDoubleVal(2), - (double)hit_fit_param->getDoubleVal(3), - (double)hit_fit_param->getDoubleVal(4) - }; - - rawHit->setFit(fit_params); - if (rawTracker_hit_fits_nav) - delete rawTracker_hit_fits_nav; - rawTracker_hit_fits_nav = nullptr; - }//raw svt hits - - return rawHit; - + EVENT::LCCollection* raw_svt_hit_fits) { + + EVENT::long64 value = + EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) | + ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 ); + decoder.setValue(value); + + RawSvtHit* rawHit = new RawSvtHit(); + rawHit->setSystem(decoder["system"]); + rawHit->setBarrel(decoder["barrel"]); + rawHit->setLayer(decoder["layer"]); + rawHit->setModule(decoder["module"]); + rawHit->setSensor(decoder["sensor"]); + rawHit->setSide(decoder["side"]); + rawHit->setStrip(decoder["strip"]); + + // Extract ADC values for this hit + int hit_adcs[6] = { + (int)rawTracker_hit->getADCValues().at(0), + (int)rawTracker_hit->getADCValues().at(1), + (int)rawTracker_hit->getADCValues().at(2), + (int)rawTracker_hit->getADCValues().at(3), + (int)rawTracker_hit->getADCValues().at(4), + (int)rawTracker_hit->getADCValues().at(5)}; + + rawHit->setADCs(hit_adcs); + if (raw_svt_hit_fits) { + UTIL::LCRelationNavigator* rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); + + // Get the list of fit params associated with the raw tracker hit + EVENT::LCObjectVec rawTracker_hit_fits_list + = rawTracker_hit_fits_nav->getRelatedToObjects(rawTracker_hit); + + // Get the list SVTFittedRawTrackerHit GenericObject associated with the SVTRawTrackerHit + IMPL::LCGenericObjectImpl* hit_fit_param + = static_cast(rawTracker_hit_fits_list.at(0)); + + double fit_params[5] = { + (double)hit_fit_param->getDoubleVal(0), + (double)hit_fit_param->getDoubleVal(1), + (double)hit_fit_param->getDoubleVal(2), + (double)hit_fit_param->getDoubleVal(3), + (double)hit_fit_param->getDoubleVal(4) + }; + + rawHit->setFit(fit_params); + if (rawTracker_hit_fits_nav) + delete rawTracker_hit_fits_nav; + rawTracker_hit_fits_nav = nullptr; + }//raw svt hits + + return rawHit; + }//build raw hit TrackerHit* utils::buildTrackerHit(IMPL::TrackerHitImpl* lc_tracker_hit) { - if (!lc_tracker_hit) - return nullptr; - - TrackerHit* tracker_hit = new TrackerHit(); - - // Get the position of the LCIO TrackerHit and set the position of - // the TrackerHit - double hit_position[3] = { - lc_tracker_hit->getPosition()[0], - lc_tracker_hit->getPosition()[1], - lc_tracker_hit->getPosition()[2] - }; - tracker_hit->setPosition(hit_position, true); - - // Set the covariance matrix of the SvtHit - tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); - - // Set the time of the SvtHit - tracker_hit->setTime(lc_tracker_hit->getTime()); - - // Set the charge of the SvtHit - tracker_hit->setCharge(lc_tracker_hit->getEDep()); - - // Set the LCIO id - tracker_hit->setID(lc_tracker_hit->id()); - - return tracker_hit; - - + if (!lc_tracker_hit) + return nullptr; + + TrackerHit* tracker_hit = new TrackerHit(); + + // Get the position of the LCIO TrackerHit and set the position of + // the TrackerHit + double hit_position[3] = { + lc_tracker_hit->getPosition()[0], + lc_tracker_hit->getPosition()[1], + lc_tracker_hit->getPosition()[2] + }; + tracker_hit->setPosition(hit_position, true); + + // Set the covariance matrix of the SvtHit + tracker_hit->setCovarianceMatrix(lc_tracker_hit->getCovMatrix()); + + // Set the time of the SvtHit + tracker_hit->setTime(lc_tracker_hit->getTime()); + + // Set the charge of the SvtHit + tracker_hit->setCharge(lc_tracker_hit->getEDep()); + + // Set the LCIO id + tracker_hit->setID(lc_tracker_hit->id()); + + return tracker_hit; + + } bool utils::addRawInfoTo3dHit(TrackerHit* tracker_hit, - IMPL::TrackerHitImpl* lc_tracker_hit, - EVENT::LCCollection* raw_svt_fits, std::vector* rawHits) { + IMPL::TrackerHitImpl* lc_tracker_hit, + EVENT::LCCollection* raw_svt_fits, std::vector* rawHits) { - if (!tracker_hit || !lc_tracker_hit) - return false; - - float rawcharge = 0; - //0 top 1 bottom - int volume = -1; - //1-6 - int layer = -1; - - //Get the Raw content of the tracker hits - EVENT::LCObjectVec lc_rawHits = lc_tracker_hit->getRawHits(); - - for (unsigned int irh = 0 ; irh < lc_rawHits.size(); ++irh) { - - //TODO useless to build all of it? - RawSvtHit* rawHit = buildRawHit(static_cast(lc_rawHits.at(irh)),raw_svt_fits); - rawcharge += rawHit->getAmp(); - int currentHitVolume = rawHit->getModule() % 2 ? 1 : 0; - int currentHitLayer = (rawHit->getLayer() - 1 ) / 2; - if (volume == -1 ) - volume = currentHitVolume; - else { - if ( currentHitVolume != volume) - std::cout<<"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent volume found" <getRawHits(); + + for (unsigned int irh = 0 ; irh < lc_rawHits.size(); ++irh) { + + //TODO useless to build all of it? + RawSvtHit* rawHit = buildRawHit(static_cast(lc_rawHits.at(irh)),raw_svt_fits); + rawcharge += rawHit->getAmp(); + int currentHitVolume = rawHit->getModule() % 2 ? 1 : 0; + int currentHitLayer = (rawHit->getLayer() - 1 ) / 2; + if (volume == -1 ) + volume = currentHitVolume; + else { + if ( currentHitVolume != volume) + std::cout<<"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent volume found" <addRawHit(rawHit); + if (rawHits) + rawHits->push_back(rawHit); - if (layer == -1 ) - layer = currentHitLayer; - else { - if (currentHitLayer != layer) - std::cout<<"[ ERROR ] : utils::addRawInfoTo3dHit raw hits with inconsistent layer found" <addRawHit(rawHit); - if (rawHits) - rawHits->push_back(rawHit); - - } - - tracker_hit->setRawCharge(rawcharge); - tracker_hit->setVolume(volume); - tracker_hit->setLayer(layer); - - return true; + + tracker_hit->setRawCharge(rawcharge); + tracker_hit->setVolume(volume); + tracker_hit->setLayer(layer); + + return true; } //TODO-improve shared finding algorithm bool utils::isUsedByTrack(IMPL::TrackerHitImpl* lc_tracker_hit, - EVENT::Track* lc_track) { - - EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); - - for (auto trk_lc_tracker_hit : trk_lc_tracker_hits) { - //std::cout<id()<<" " <id()< id() == trk_lc_tracker_hit -> id()) - return true; - } - return false; + EVENT::Track* lc_track) { + + EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); + + for (auto trk_lc_tracker_hit : trk_lc_tracker_hits) { + //std::cout<id()<<" " <id()< id() == trk_lc_tracker_hit -> id()) + return true; + } + return false; } bool utils::isUsedByTrack(TrackerHit* tracker_hit, - EVENT::Track* lc_track) { - - EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); - - for (auto trk_lc_tracker_hit : trk_lc_tracker_hits) { - if (tracker_hit->getID() == trk_lc_tracker_hit->id()) - return true; - } - return false; + EVENT::Track* lc_track) { + + EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); + + for (auto trk_lc_tracker_hit : trk_lc_tracker_hits) { + if (tracker_hit->getID() == trk_lc_tracker_hit->id()) + return true; + } + return false; } From bddec04e716e031301d70817d04eff41f574a2a1 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 29 Oct 2019 08:48:04 -0700 Subject: [PATCH 157/314] Add histo class for Reco Hit Analysis --- analysis/include/RecoHitAnaHistos.h | 30 +++++++++++++ analysis/src/RecoHitAnaHistos.cxx | 65 +++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 analysis/include/RecoHitAnaHistos.h create mode 100644 analysis/src/RecoHitAnaHistos.cxx diff --git a/analysis/include/RecoHitAnaHistos.h b/analysis/include/RecoHitAnaHistos.h new file mode 100644 index 000000000..2dcdbd264 --- /dev/null +++ b/analysis/include/RecoHitAnaHistos.h @@ -0,0 +1,30 @@ +#ifndef RECOHIT_ANAHISTOS_H +#define RECOHIT_ANAHISTOS_H + +// HPSTR +#include "HistoManager.h" +#include "TrackerHit.h" +#include "Track.h" +#include "CalHit.h" +#include "CalCluster.h" +#include +#include + +class RecoHitAnaHistos : public HistoManager { + + public: + + RecoHitAnaHistos(const std::string& inputName) : HistoManager(inputName) { m_name = inputName; }; + + virtual void Define3DHistos(){}; + virtual void Define2DHistos(){}; + virtual void Define1DHistos(); + + void FillTrackerHits(std::vector *trkrHits, float weight = 1.); + void FillTracks(std::vector *tracks, float weight = 1.); + void FillEcalHits(std::vector *ecalHits, float weight = 1.); + void FillEcalClusters(std::vector *ecalClusters, float weight = 1.); + +}; + +#endif //RECOHIT_ANAHISTOS_H diff --git a/analysis/src/RecoHitAnaHistos.cxx b/analysis/src/RecoHitAnaHistos.cxx new file mode 100644 index 000000000..95a14e9d8 --- /dev/null +++ b/analysis/src/RecoHitAnaHistos.cxx @@ -0,0 +1,65 @@ +#include "RecoHitAnaHistos.h" +#include + +void RecoHitAnaHistos::Define1DHistos() { + + // init TrackerHit Histos + histos1d["numTrkrHits_h"] = new TH1F("numTrkrHits_h", ";Number of Reco Tracker Hits;Events", + 30, -0.5, 29.5); + histos1d["trkrHitEdep_h"] = new TH1F("trkrHitEdep_h", + ";Tracker Hit Energy [arb. units];Tracker Hits / 1 arb. unit", + 100, 0, 100); + + // init Track Histos + histos1d["numTracks_h"] = new TH1F("numTracks_h", ";Number of GBL Tracks;Events", + 10, -0.5, 9.5); + + // init Ecal Hit Histos + histos1d["numEcalHits_h"] = new TH1F("numEcalHits_h", ";Number of Reco Ecal Hits;Events", + 10, -0.5, 9.5); + histos1d["ecalHitEnergy_h"] = new TH1F("ecalHitEnergy_h", + ";Reco Ecal Hit Energy [MeV];Ecal Hits / 2 MeV", + 200, 0, 400); + + // init Ecal Cluster Histos + histos1d["numEcalClusters_h"] = new TH1F("numEcalClusters_h", ";Number of Reco Ecal Clusters;Events", + 10, -0.5, 9.5); + histos1d["ecalClusterEnergy_h"] = new TH1F("ecalClusterEnergy_h",";Reco Ecal Cluster Energy [MeV];Clusters / 2 MeV", + 200, 0, 400); + sumw2(); +} + +void RecoHitAnaHistos::FillTrackerHits(std::vector *trkrHits, float weight ) { + int nHits = trkrHits->size(); + histos1d["numTrkrHits_h"]->Fill((float)nHits, weight); + for (int i=0; i < nHits; i++) + { + TrackerHit *hit = trkrHits->at(i); + histos1d["trkrHitEdep_h"]->Fill(hit->getCharge()*1000000.0, weight); // Scaled to MeV + } +} + +void RecoHitAnaHistos::FillTracks(std::vector *tracks, float weight ) { + int nTracks = tracks->size(); + histos1d["numTracks_h"]->Fill((float)nTracks, weight); +} + +void RecoHitAnaHistos::FillEcalHits(std::vector *ecalHits, float weight ) { + int nHits = ecalHits->size(); + histos1d["numEcalHits_h"]->Fill((float)nHits, weight); + for (int i=0; i < nHits; i++) + { + CalHit *hit = ecalHits->at(i); + histos1d["ecalHitEnergy_h"]->Fill(hit->getEnergy()*1000.0, weight); // Scaled to MeV + } +} + +void RecoHitAnaHistos::FillEcalClusters(std::vector *ecalClusters, float weight ) { + int nClusters = ecalClusters->size(); + histos1d["numEcalClusters_h"]->Fill((float)nClusters, weight); + for (int i=0; i < nClusters; i++) + { + CalCluster *cluster = ecalClusters->at(i); + histos1d["ecalClusterEnergy_h"]->Fill(cluster->getEnergy()*1000.0, weight); // Scaled to MeV + } +} From 81ea430d5846720eaedb3971cfcc9e4e7d240beb Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 29 Oct 2019 08:48:52 -0700 Subject: [PATCH 158/314] AnaProcessor for Reco Hit analysis --- processors/include/RecoHitAnaProcessor.h | 57 ++++++++++++++++++++++++ processors/src/RecoHitAnaProcessor.cxx | 50 +++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 processors/include/RecoHitAnaProcessor.h create mode 100644 processors/src/RecoHitAnaProcessor.cxx diff --git a/processors/include/RecoHitAnaProcessor.h b/processors/include/RecoHitAnaProcessor.h new file mode 100644 index 000000000..de959fde9 --- /dev/null +++ b/processors/include/RecoHitAnaProcessor.h @@ -0,0 +1,57 @@ +#ifndef __RECOHIT_ANAPROCESSOR_H__ +#define __RECOHIT_ANAPROCESSOR_H__ + +//HPSTR +#include "HpsEvent.h" +#include "Collections.h" +#include "Track.h" +#include "TrackerHit.h" +#include "RecoHitAnaHistos.h" + + +//ROOT +#include "Processor.h" +#include "TClonesArray.h" +#include "TBranch.h" +#include "TTree.h" +#include "TFile.h" + +class TTree; + + +class RecoHitAnaProcessor : public Processor { + + public: + + RecoHitAnaProcessor(const std::string& name, Process& process); + + ~RecoHitAnaProcessor(); + + virtual bool process(IEvent* ievent); + + virtual void initialize(TTree* tree); + + virtual void finalize(); + + virtual void configure(const ParameterSet& parameters); + + private: + + RecoHitAnaHistos* histos{nullptr}; + + //TODO Change this to be held from HPSEvent + TTree* tree_; + TBranch* btrkrHits_{nullptr}; + TBranch* btracks_{nullptr}; + TBranch* becalHits_{nullptr}; + TBranch* becalClusters_{nullptr}; + + std::vector * trkrHits_{}; + std::vector * tracks_{}; + std::vector * ecalHits_{}; + std::vector * ecalClusters_{}; + +}; + + +#endif diff --git a/processors/src/RecoHitAnaProcessor.cxx b/processors/src/RecoHitAnaProcessor.cxx new file mode 100644 index 000000000..3596dba53 --- /dev/null +++ b/processors/src/RecoHitAnaProcessor.cxx @@ -0,0 +1,50 @@ +/** + * @file RecoHitAnaProcessor.cxx + * @brief AnaProcessor used fill histograms to compare simulations + * @author Cameron Bravo, SLAC National Accelerator Laboratory + */ +#include "RecoHitAnaProcessor.h" +#include + +RecoHitAnaProcessor::RecoHitAnaProcessor(const std::string& name, Process& process) : Processor(name,process){} +//TODO CHECK THIS DESTRUCTOR +RecoHitAnaProcessor::~RecoHitAnaProcessor(){} + + +void RecoHitAnaProcessor::configure(const ParameterSet& parameters) { + +} + +void RecoHitAnaProcessor::initialize(TTree* tree) { + tree_= tree; + // init histos + histos = new RecoHitAnaHistos("recoHitAna"); + histos->Define1DHistos(); + //histos->Define2DHistos(); + + // init TTree + tree_->SetBranchAddress(Collections::TRACKER_HITS , &trkrHits_ , &btrkrHits_ ); + tree_->SetBranchAddress(Collections::GBL_TRACKS , &tracks_ , &btracks_ ); + tree_->SetBranchAddress(Collections::ECAL_HITS , &ecalHits_ , &becalHits_ ); + tree_->SetBranchAddress(Collections::ECAL_CLUSTERS, &ecalClusters_, &becalClusters_); + +} + +bool RecoHitAnaProcessor::process(IEvent* ievent) { + + histos->FillTrackerHits(trkrHits_); + histos->FillTracks(tracks_); + histos->FillEcalHits(ecalHits_); + histos->FillEcalClusters(ecalClusters_); + + return true; +} + +void RecoHitAnaProcessor::finalize() { + + histos->saveHistos(outF_,""); + delete histos; + histos = nullptr; +} + +DECLARE_PROCESSOR(RecoHitAnaProcessor); From 06270d39088c3825c92d8364faec88d362df0c98 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 29 Oct 2019 15:20:03 -0700 Subject: [PATCH 159/314] minor changes made in pyplot --- processors/src/MCTrackerHitProcessor.cxx | 11 ++++++++--- pyplot/compareMC.py | 7 ++++--- pyplot/utilities.py | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/processors/src/MCTrackerHitProcessor.cxx b/processors/src/MCTrackerHitProcessor.cxx index 96692a841..be1b6b79c 100644 --- a/processors/src/MCTrackerHitProcessor.cxx +++ b/processors/src/MCTrackerHitProcessor.cxx @@ -33,7 +33,7 @@ bool MCTrackerHitProcessor::process(IEvent* ievent) { trackerhits_->Clear(); for (int ihit = 0; ihit < lcio_trackerhits->getNumberOfElements(); ++ihit) { - // Get a 3D hit from the list of hits + // Get a 3D hit from the list of hits EVENT::SimTrackerHit* lcio_mcTracker_hit = static_cast(lcio_trackerhits->getElementAt(ihit)); //Decode the cellid @@ -49,13 +49,18 @@ bool MCTrackerHitProcessor::process(IEvent* ievent) { mc_tracker_hit->setModule(decoder["module"]); // Set the position of the hit - mc_tracker_hit->setPosition(lcio_mcTracker_hit->getPosition()); + double hitPos[3]; + hitPos[0] = lcio_mcTracker_hit->getPosition()[0]; + hitPos[1] = lcio_mcTracker_hit->getPosition()[1]; + hitPos[2] = lcio_mcTracker_hit->getPosition()[2]; + mc_tracker_hit->setPosition(hitPos); // Set the energy deposit of the hit mc_tracker_hit->setEdep(lcio_mcTracker_hit->getEDep()); // Set the pdg of particle generating the hit - mc_tracker_hit->setPDG(lcio_mcTracker_hit->getMCParticle()->getPDG()); + if(lcio_mcTracker_hit->getMCParticle()) + mc_tracker_hit->setPDG(lcio_mcTracker_hit->getMCParticle()->getPDG()); // Set the time of the hit mc_tracker_hit->setTime(lcio_mcTracker_hit->getTime()); diff --git a/pyplot/compareMC.py b/pyplot/compareMC.py index 558f325e7..d2b15d844 100755 --- a/pyplot/compareMC.py +++ b/pyplot/compareMC.py @@ -8,14 +8,15 @@ path = "/home/bravo/hps3/users/bravo/sim/det16/singleMuon/" inFileList = [ "slic/slicSingleMu4deg_anaMC.root", - "hps-sim/muonHpsSim_anaMC.root"] + "hps-sim/muonHpsSim_anaMC.root", + "ldmx-sim/muonLdmxSim_anaMC.root"] colors = [r.kBlack, r.kRed, r.kBlue, r.kGreen+2, r.kOrange-2] inputFiles = [] -legends = ["slic","hps-sim"] +legends = ["slic","hps-sim","ldmx-sim"] outdir = "./" if not os.path.exists(outdir): @@ -38,7 +39,7 @@ histos[i_f].SetMarkerColor(colors[i_f]) histos[i_f].SetLineColor(colors[i_f]) pass - canvs.append(utils.MakePlot(key.GetName(),outdir,histos,legends,".png",LogY=True)) + canvs.append(utils.MakePlot(key.GetName(),outdir,histos,legends,".png",LogY=True,RatioType="Sequential")) pass outF = r.TFile("slicSingleMu_compMC.root","RECREATE") diff --git a/pyplot/utilities.py b/pyplot/utilities.py index 0b2d76c33..e58afadff 100755 --- a/pyplot/utilities.py +++ b/pyplot/utilities.py @@ -325,7 +325,7 @@ def MakePlot(name,outdir,histos,legends,oFext,xtitle="",ytitle="",ymin=0,ymax=1, ForRatio.SetMaximum(100.) ForRatio.Divide(reference) - ForRatio.DrawCopy("hist PX0 same") + ForRatio.DrawCopy("pe same") elif (RatioType=="Alternate"): From f3ac0b55fcae74899b1fccb6a0905915df57700d Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Tue, 29 Oct 2019 15:24:58 -0700 Subject: [PATCH 160/314] Another minor change to pyplot --- pyplot/compareMC.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyplot/compareMC.py b/pyplot/compareMC.py index d2b15d844..5becc8412 100755 --- a/pyplot/compareMC.py +++ b/pyplot/compareMC.py @@ -8,15 +8,14 @@ path = "/home/bravo/hps3/users/bravo/sim/det16/singleMuon/" inFileList = [ "slic/slicSingleMu4deg_anaMC.root", - "hps-sim/muonHpsSim_anaMC.root", - "ldmx-sim/muonLdmxSim_anaMC.root"] + "hps-sim/muonHpsSim_anaMC.root"] colors = [r.kBlack, r.kRed, r.kBlue, r.kGreen+2, r.kOrange-2] inputFiles = [] -legends = ["slic","hps-sim","ldmx-sim"] +legends = ["slic","hps-sim"] outdir = "./" if not os.path.exists(outdir): From dd3098441a80b86236fca5d2720579d259ccee15 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Wed, 30 Oct 2019 11:23:23 -0400 Subject: [PATCH 161/314] Minor modification to accomodate the Python 3.4.3 distribution at JLab. --- processing/src/ConfigurePython.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/processing/src/ConfigurePython.cxx b/processing/src/ConfigurePython.cxx index cd5ac5cc5..aa9852ebb 100644 --- a/processing/src/ConfigurePython.cxx +++ b/processing/src/ConfigurePython.cxx @@ -58,10 +58,16 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], if (nargs > 0) { #if PY_MAJOR_VERSION >= 3 wchar_t** targs = new wchar_t*[nargs + 1]; +#if PY_MINOR_VERION >=5 targs[0] = Py_DecodeLocale(python_script.c_str(),NULL); for (int i = 0; i < nargs; i++) targs[i + 1] = Py_DecodeLocale(args[i],NULL); - +#else + targs[0] = PyUnicode_AsUnicode(PyUnicode_DecodeLocale(python_script.c_str(),NULL)); + for (int i = 0; i < nargs; i++) + targs[i + 1] = PyUnicode_AsUnicode(PyUnicode_DecodeLocale(args[i],NULL)); + +#endif PySys_SetArgv(nargs+1, targs); delete[] targs; #else From 1c25794dacd6bad419f7cccc1978871baa73adad Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Wed, 30 Oct 2019 11:59:07 -0400 Subject: [PATCH 162/314] Cleanup temporary pointer properly with Py_DECREF --- processing/src/ConfigurePython.cxx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/processing/src/ConfigurePython.cxx b/processing/src/ConfigurePython.cxx index aa9852ebb..1ca66494b 100644 --- a/processing/src/ConfigurePython.cxx +++ b/processing/src/ConfigurePython.cxx @@ -58,14 +58,20 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], if (nargs > 0) { #if PY_MAJOR_VERSION >= 3 wchar_t** targs = new wchar_t*[nargs + 1]; -#if PY_MINOR_VERION >=5 + +#if PY_MINOR_VERSION >=5 // Python 3.4 is missing the Py_DecodeLocale() method. targs[0] = Py_DecodeLocale(python_script.c_str(),NULL); for (int i = 0; i < nargs; i++) targs[i + 1] = Py_DecodeLocale(args[i],NULL); -#else - targs[0] = PyUnicode_AsUnicode(PyUnicode_DecodeLocale(python_script.c_str(),NULL)); - for (int i = 0; i < nargs; i++) - targs[i + 1] = PyUnicode_AsUnicode(PyUnicode_DecodeLocale(args[i],NULL)); +#else // Code for Python 3.4, where Py_DecodeLocale is missing. + PyObject *tmpstr = PyUnicode_DecodeLocale(python_script.c_str(),NULL); + targs[0] = PyUnicode_AsUnicode(tmpstr); + Py_DECREF(tmpstr); + for (int i = 0; i < nargs; i++){ + tmpstr = PyUnicode_DecodeLocale(args[i],NULL); + targs[i + 1] = PyUnicode_AsUnicode(tmpstr); + Py_DECREF(tmpstr); + } #endif PySys_SetArgv(nargs+1, targs); From 37fc112aba2f1a29c3f17bc0b6ee2122ad19bfdf Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 31 Oct 2019 12:37:33 -0700 Subject: [PATCH 163/314] Moved bare to smart pointers in utilities.cxx --- processors/src/utilities.cxx | 59 +++++++++++++++++------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/processors/src/utilities.cxx b/processors/src/utilities.cxx index da178ba51..18554b2ea 100644 --- a/processors/src/utilities.cxx +++ b/processors/src/utilities.cxx @@ -1,5 +1,6 @@ #include "utilities.h" #include +#include /* void utils::buildTrackCollection(std::vector& tracks, Event* event, @@ -93,61 +94,57 @@ Track* utils::buildTrack(EVENT::Track* lc_track, if (gbl_kink_data) { // Instantiate an LCRelation navigator which will allow faster access // to GBLKinkData object - UTIL::LCRelationNavigator* gbl_kink_data_nav - = new UTIL::LCRelationNavigator(gbl_kink_data); - + std::shared_ptr gbl_kink_data_nav = std::make_shared(gbl_kink_data); + // Get the list of GBLKinkData associated with the LCIO Track EVENT::LCObjectVec gbl_kink_data_list = gbl_kink_data_nav->getRelatedFromObjects(lc_track); - + // The container of GBLKinkData objects should only contain a // single object. If not, throw an exception if (gbl_kink_data_list.size() != 1) { throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA_REL) - + " has the wrong data structure."); + + std::string(Collections::TRACK_DATA_REL) + + " has the wrong data structure."); } - + // Get the list GBLKinkData GenericObject associated with the LCIO Track IMPL::LCGenericObjectImpl* gbl_kink_datum = static_cast(gbl_kink_data_list.at(0)); - + // Set the lambda and phi kink values for (int ikink = 0; ikink < gbl_kink_datum->getNDouble(); ++ikink) { track->setLambdaKink(ikink, gbl_kink_datum->getFloatVal(ikink)); track->setPhiKink(ikink, gbl_kink_datum->getDoubleVal(ikink)); } - - delete gbl_kink_data_nav; - + } // add gbl kink data - + if (track_data) { - + // Instantiate an LCRelation navigator which will allow faster access // to TrackData objects - UTIL::LCRelationNavigator* track_data_nav - = new UTIL::LCRelationNavigator(track_data); - + std::shared_ptr track_data_nav = std::make_shared(track_data); + // Get the list of TrackData associated with the LCIO Track EVENT::LCObjectVec track_data_list = track_data_nav->getRelatedFromObjects(lc_track); - + // The container of TrackData objects should only contain a single // object. If not, throw an exception. if (track_data_list.size() == 1) { - + // Get the TrackData GenericObject associated with the LCIO Track IMPL::LCGenericObjectImpl* track_datum = static_cast(track_data_list.at(0)); - + // Check that the TrackData data structure is correct. If it's // not, throw a runtime exception. if (track_datum->getNDouble() > 14 || track_datum->getNFloat() != 1 - || track_datum->getNInt() != 1) { + || track_datum->getNInt() != 1) { throw std::runtime_error("[ TrackingProcessor ]: The collection " - + std::string(Collections::TRACK_DATA) - + " has the wrong structure."); + + std::string(Collections::TRACK_DATA) + + " has the wrong structure."); } - + // Set the SvtTrack isolation values for (int iso_index = 0; iso_index < track_datum->getNDouble(); ++iso_index) { track->setIsolation(iso_index, track_datum->getDoubleVal(iso_index)); @@ -155,25 +152,24 @@ Track* utils::buildTrack(EVENT::Track* lc_track, // Set the SvtTrack time track->setTrackTime(track_datum->getFloatVal(0)); - + // Set the volume (top/bottom) in which the SvtTrack resides track->setTrackVolume(track_datum->getIntVal(0)); } - delete track_data_nav; - + } //add track data return track; } RawSvtHit* utils::buildRawHit(EVENT::TrackerRawData* rawTracker_hit, - EVENT::LCCollection* raw_svt_hit_fits) { + EVENT::LCCollection* raw_svt_hit_fits) { EVENT::long64 value = EVENT::long64(rawTracker_hit->getCellID0() & 0xffffffff) | ( EVENT::long64(rawTracker_hit->getCellID1() ) << 32 ); decoder.setValue(value); - + RawSvtHit* rawHit = new RawSvtHit(); rawHit->setSystem(decoder["system"]); rawHit->setBarrel(decoder["barrel"]); @@ -194,7 +190,8 @@ RawSvtHit* utils::buildRawHit(EVENT::TrackerRawData* rawTracker_hit, rawHit->setADCs(hit_adcs); if (raw_svt_hit_fits) { - UTIL::LCRelationNavigator* rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits); + std::shared_ptr rawTracker_hit_fits_nav = std::make_shared(raw_svt_hit_fits); + // Get the list of fit params associated with the raw tracker hit EVENT::LCObjectVec rawTracker_hit_fits_list @@ -213,9 +210,7 @@ RawSvtHit* utils::buildRawHit(EVENT::TrackerRawData* rawTracker_hit, }; rawHit->setFit(fit_params); - if (rawTracker_hit_fits_nav) - delete rawTracker_hit_fits_nav; - rawTracker_hit_fits_nav = nullptr; + }//raw svt hits return rawHit; From b18bd890266d92a99e0be5ac13ae56f5cce8d8fe Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Thu, 31 Oct 2019 14:19:50 -0700 Subject: [PATCH 164/314] Correct indentation --- processors/src/utilities.cxx | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/processors/src/utilities.cxx b/processors/src/utilities.cxx index 18554b2ea..bed7d6ad3 100644 --- a/processors/src/utilities.cxx +++ b/processors/src/utilities.cxx @@ -2,15 +2,15 @@ #include #include /* - void utils::buildTrackCollection(std::vector& tracks, - Event* event, - const char* LCTrackCollection) - { + void utils::buildTrackCollection(std::vector& tracks, + Event* event, + const char* LCTrackCollection) + { - EVENT::LCCollection* lc_tracks event->getLCCollection(LCTrackCollection); + EVENT::LCCollection* lc_tracks event->getLCCollection(LCTrackCollection); - } + } */ @@ -54,8 +54,8 @@ Vertex* utils::buildVertex(EVENT::Vertex* lc_vertex) { } Track* utils::buildTrack(EVENT::Track* lc_track, - EVENT::LCCollection* gbl_kink_data, - EVENT::LCCollection* track_data) { + EVENT::LCCollection* gbl_kink_data, + EVENT::LCCollection* track_data) { if (!lc_track) return nullptr; @@ -63,10 +63,10 @@ Track* utils::buildTrack(EVENT::Track* lc_track, Track* track = new Track(); // Set the track parameters track->setTrackParameters(lc_track->getD0(), - lc_track->getPhi(), - lc_track->getOmega(), - lc_track->getTanLambda(), - lc_track->getZ0()); + lc_track->getPhi(), + lc_track->getOmega(), + lc_track->getTanLambda(), + lc_track->getZ0()); // Set the track type track->setType(lc_track->getType()); @@ -252,8 +252,8 @@ TrackerHit* utils::buildTrackerHit(IMPL::TrackerHitImpl* lc_tracker_hit) { } bool utils::addRawInfoTo3dHit(TrackerHit* tracker_hit, - IMPL::TrackerHitImpl* lc_tracker_hit, - EVENT::LCCollection* raw_svt_fits, std::vector* rawHits) { + IMPL::TrackerHitImpl* lc_tracker_hit, + EVENT::LCCollection* raw_svt_fits, std::vector* rawHits) { if (!tracker_hit || !lc_tracker_hit) return false; @@ -305,7 +305,7 @@ bool utils::addRawInfoTo3dHit(TrackerHit* tracker_hit, //TODO-improve shared finding algorithm bool utils::isUsedByTrack(IMPL::TrackerHitImpl* lc_tracker_hit, - EVENT::Track* lc_track) { + EVENT::Track* lc_track) { EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); @@ -318,7 +318,7 @@ bool utils::isUsedByTrack(IMPL::TrackerHitImpl* lc_tracker_hit, } bool utils::isUsedByTrack(TrackerHit* tracker_hit, - EVENT::Track* lc_track) { + EVENT::Track* lc_track) { EVENT::TrackerHitVec trk_lc_tracker_hits = lc_track->getTrackerHits(); From efdff42f0c2577c6191139190211808f8ce9d74c Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Fri, 1 Nov 2019 09:46:28 -0700 Subject: [PATCH 165/314] Add a few configuration files --- processors/config/anaMCTuple_cfg.py | 29 ++++++++++++++++++++++++ processors/config/mcTuple_cfg.py | 33 ++++++++++++++++++++++++++++ processors/config/recoTuple_cfg.py | 34 +++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 processors/config/anaMCTuple_cfg.py create mode 100644 processors/config/mcTuple_cfg.py create mode 100644 processors/config/recoTuple_cfg.py diff --git a/processors/config/anaMCTuple_cfg.py b/processors/config/anaMCTuple_cfg.py new file mode 100644 index 000000000..8805850e8 --- /dev/null +++ b/processors/config/anaMCTuple_cfg.py @@ -0,0 +1,29 @@ +import HpstrConf +import sys + +# Use the input file to set the output file name +infile = sys.argv[1].strip() +outfile = '%s_anaMC.root' % infile[:-5] + +print 'Input file: %s' % infile +print 'Output file: %s' % outfile + +p = HpstrConf.Process() + +# Library containing processors +p.libraries.append("libprocessors.so") + +############################### +# Processors # +############################### + +mcana = HpstrConf.Processor('mcana', 'MCAnaProcessor') +# Sequence which the processors will run. +p.sequence = [mcana] + +p.input_files=[infile] +p.output_files = [outfile] + +#p.max_events = 1000 + +p.printProcess() diff --git a/processors/config/mcTuple_cfg.py b/processors/config/mcTuple_cfg.py new file mode 100644 index 000000000..e80ac8645 --- /dev/null +++ b/processors/config/mcTuple_cfg.py @@ -0,0 +1,33 @@ +import HpstrConf +import sys + +# Use the input file to set the output file name +lcio_file = sys.argv[1].strip() +root_file = '%s.root' % lcio_file[:-6] + +print('LCIO file: %s' % lcio_file) +print('Root file: %s' % root_file) + +p = HpstrConf.Process() + +# Library containing processors +p.libraries.append("libprocessors.so") + +############################### +# Processors # +############################### + +mcpart = HpstrConf.Processor('mcpart', 'MCParticleProcessor') +mcthits = HpstrConf.Processor('mcthits', 'MCTrackerHitProcessor') +mcehits = HpstrConf.Processor('mcehits', 'MCEcalHitProcessor') + +# Sequence which the processors will run. +p.sequence = [mcpart, mcthits, mcehits] +#p.sequence = [mcpart] + +p.input_files=[lcio_file] +p.output_files = [root_file] + +#p.max_events = 1000 + +p.printProcess() diff --git a/processors/config/recoTuple_cfg.py b/processors/config/recoTuple_cfg.py new file mode 100644 index 000000000..d76edb6d9 --- /dev/null +++ b/processors/config/recoTuple_cfg.py @@ -0,0 +1,34 @@ +import HpstrConf +import sys + +# Use the input file to set the output file name +lcio_file = sys.argv[1].strip() +root_file = '%s.root' % lcio_file[:-6] + +print 'LCIO file: %s' % lcio_file +print 'Root file: %s' % root_file + +p = HpstrConf.Process() + +# Library containing processors +p.libraries.append("libprocessors.so") + +############################### +# Processors # +############################### + +header = HpstrConf.Processor('header', 'EventProcessor') +track = HpstrConf.Processor('svt', 'TrackingProcessor') +#track = HpstrConf.Processor('svt', 'SvtDataProcessor') +ecal = HpstrConf.Processor('ecal', 'ECalDataProcessor') +mcpart = HpstrConf.Processor('mcpart', 'MCParticleProcessor') + +# Sequence which the processors will run. +p.sequence = [header, track, ecal, mcpart] + +p.input_files=[lcio_file] +p.output_files = [root_file] + +#p.max_events = 1000 + +p.printProcess() From 8d42a2b6e13a8734631ebc44e6525229c2ef3b96 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 1 Nov 2019 21:53:54 -0400 Subject: [PATCH 166/314] Update the Python 3.4 compatibility issue to work at JLab. Also, properly free targs memory. --- processing/src/ConfigurePython.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/processing/src/ConfigurePython.cxx b/processing/src/ConfigurePython.cxx index 1ca66494b..1a0b95eda 100644 --- a/processing/src/ConfigurePython.cxx +++ b/processing/src/ConfigurePython.cxx @@ -64,17 +64,18 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], for (int i = 0; i < nargs; i++) targs[i + 1] = Py_DecodeLocale(args[i],NULL); #else // Code for Python 3.4, where Py_DecodeLocale is missing. - PyObject *tmpstr = PyUnicode_DecodeLocale(python_script.c_str(),NULL); - targs[0] = PyUnicode_AsUnicode(tmpstr); + PyObject *tmpstr = PyUnicode_FromString(python_script.c_str()); + targs[0] = PyUnicode_AsWideCharString(tmpstr,NULL); Py_DECREF(tmpstr); for (int i = 0; i < nargs; i++){ - tmpstr = PyUnicode_DecodeLocale(args[i],NULL); - targs[i + 1] = PyUnicode_AsUnicode(tmpstr); + tmpstr = PyUnicode_FromString(args[i]); + targs[i + 1] = PyUnicode_AsWideCharString(tmpstr,NULL); Py_DECREF(tmpstr); } #endif - PySys_SetArgv(nargs+1, targs); + PySys_SetArgvEx(nargs+1, targs,1); + for(int i=0;i Date: Sat, 2 Nov 2019 11:52:04 -0400 Subject: [PATCH 167/314] Add Process.add_library() to help resolve lib paths and extensions. --- processing/python/HpstrConf.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/processing/python/HpstrConf.py b/processing/python/HpstrConf.py index 16de1b8dc..84b1b3e31 100644 --- a/processing/python/HpstrConf.py +++ b/processing/python/HpstrConf.py @@ -1,3 +1,4 @@ +from ctypes.util import find_library class Processor: @@ -25,6 +26,12 @@ def __init__(self): self.libraries = [] Process.lastProcess=self + def add_library(self,lib): + '''Add a libraries to the list of libraries to load, searching the appropriate paths to find it, + and adding the correct file extension''' + add_lib = find_library(lib) + self.libraries.append(add_lib) + def printProcess(self): if (self.max_events > 0): print(" Maximum events to process: %d" % (self.max_events)) From 0c89443424c61b857aa33a4769789ad6f177d9fd Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Sat, 2 Nov 2019 11:54:01 -0400 Subject: [PATCH 168/314] Make use of improved Process.add_library(), make print P3 friendly. --- processors/config/dst.py | 6 +++--- processors/config/rawSvtHits_cfg.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/processors/config/dst.py b/processors/config/dst.py index 7dc05a199..eca6cd6b1 100644 --- a/processors/config/dst.py +++ b/processors/config/dst.py @@ -5,13 +5,13 @@ lcio_file = sys.argv[1].strip() root_file = '%s.root' % lcio_file[:-6] -print 'LCIO file: %s' % lcio_file -print 'Root file: %s' % root_file +print('LCIO file: %s' % lcio_file) +print('Root file: %s' % root_file) p = HpstrConf.Process() # Library containing processors -p.libraries.append("libprocessors.so") +p.add_library("libprocessors") ############################### # Processors # diff --git a/processors/config/rawSvtHits_cfg.py b/processors/config/rawSvtHits_cfg.py index 1c00910bf..9ba419ca1 100644 --- a/processors/config/rawSvtHits_cfg.py +++ b/processors/config/rawSvtHits_cfg.py @@ -6,13 +6,13 @@ root_file = '%s.root' % lcio_file[:-6] root_file = 'testRun.root' -print 'LCIO file: %s' % lcio_file -print 'Root file: %s' % root_file +print('LCIO file: %s' % lcio_file) +print('Root file: %s' % root_file) p = HpstrConf.Process() # Library containing processors -p.libraries.append("libprocessors.so") +p.add_library("libprocessors") ############################### # Processors # From e87a5d00d4f3c673326614cfb227f5cbc2f859c8 Mon Sep 17 00:00:00 2001 From: Cameron Bravo Date: Mon, 11 Nov 2019 12:52:18 -0800 Subject: [PATCH 169/314] Add processor to read 3D tracker hits from LCIO --- event/include/Collections.h | 3 + processors/include/Tracker3DHitProcessor.h | 78 ++++++++++++++++++++++ processors/src/Tracker3DHitProcessor.cxx | 55 +++++++++++++++ processors/src/TrackingProcessor.cxx | 2 +- 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 processors/include/Tracker3DHitProcessor.h create mode 100644 processors/src/Tracker3DHitProcessor.cxx diff --git a/event/include/Collections.h b/event/include/Collections.h index b5093767f..897c1cc98 100644 --- a/event/include/Collections.h +++ b/event/include/Collections.h @@ -28,6 +28,9 @@ namespace Collections { /** Name of the tracker hits collection. */ constexpr const char* TRACKER_HITS{"RotatedHelicalTrackHits"}; + /** Name of the tracker hits on track collection. */ + constexpr const char* TRACKER_HITS_ON_TRACK{"RotatedHelicalOnTrackHits"}; + /** The name of the collection containing GBL kink data GenericObjects */ constexpr const char* KINK_DATA{"GBLKinkData"}; diff --git a/processors/include/Tracker3DHitProcessor.h b/processors/include/Tracker3DHitProcessor.h new file mode 100644 index 000000000..342000372 --- /dev/null +++ b/processors/include/Tracker3DHitProcessor.h @@ -0,0 +1,78 @@ +/** + * + */ + +#ifndef __TRACKER3DHIT_PROCESSOR_H__ +#define __TRACKER3DHIT_PROCESSOR_H__ + +//-----------------// +// C++ StdLib // +//-----------------// +#include +#include +#include + +//----------// +// LCIO // +//----------// +#include +#include +#include +#include +#include + +//-----------// +// hpstr // +//-----------// +#include "Collections.h" +#include "Processor.h" +#include "Track.h" +#include "TrackerHit.h" +#include "Event.h" + +// Forward declarations +class TTree; + +class Tracker3DHitProcessor : public Processor { + + public: + + /** + * Class constructor. + * + * @param name Name for this instance of the class. + * @param process The Process class associated with Processor, provided + * by the processing framework. + */ + Tracker3DHitProcessor(const std::string& name, Process& process); + + /** Destructor */ + ~Tracker3DHitProcessor(); + + /** + * Process the event and put new data products into it. + * @param event The Event to process. + */ + virtual bool process(IEvent* ievent); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events starts. + */ + virtual void initialize(TTree* tree); + + /** + * Callback for the Processor to take any necessary + * action when the processing of events finishes. + */ + virtual void finalize(); + + private: + + /** Container to hold all TrackerHit objects. */ + std::vector hits_; + + +}; // Tracker3DHitProcessor + +#endif // __TRACKER3DHIT_PROCESSOR_H__ diff --git a/processors/src/Tracker3DHitProcessor.cxx b/processors/src/Tracker3DHitProcessor.cxx new file mode 100644 index 000000000..9dfa9b858 --- /dev/null +++ b/processors/src/Tracker3DHitProcessor.cxx @@ -0,0 +1,55 @@ +#include "Tracker3DHitProcessor.h" +#include "utilities.h" + +Tracker3DHitProcessor::Tracker3DHitProcessor(const std::string& name, Process& process) + : Processor(name, process) { +} + +Tracker3DHitProcessor::~Tracker3DHitProcessor() { +} + +void Tracker3DHitProcessor::initialize(TTree* tree) { + // Add branches to tree + tree->Branch(Collections::TRACKER_HITS, &hits_); +} + +bool Tracker3DHitProcessor::process(IEvent* ievent) { + + for(int i = 0; i < hits_.size(); i++) delete hits_.at(i); + hits_.clear(); + + Event* event = static_cast (ievent); + + // Get the collection of 3D hits from the LCIO event. If no such collection + // exist, a DataNotAvailableException is thrown + EVENT::LCCollection* tracker_hits = event->getLCCollection(Collections::TRACKER_HITS); + + // Create a map from an LCIO TrackerHit to a SvtHit. This will be used when + // assigning references to a track + // TODO: Use an unordered map for faster access + std::map hit_map; + + // Loop over all of the 3D hits in the LCIO event and add them to the + // HPS event + for (int ihit = 0; ihit < tracker_hits->getNumberOfElements(); ++ihit) { + + // Get a 3D hit from the list of hits + IMPL::TrackerHitImpl* lc_tracker_hit = static_cast(tracker_hits->getElementAt(ihit)); + + // Build a TrackerHit + TrackerHit* tracker_hit = utils::buildTrackerHit(lc_tracker_hit); + + // Map the TrackerHit object to the corresponding SvtHit object. This + // will be used later when setting references for hits on tracks. + hit_map[lc_tracker_hit] = tracker_hit; + hits_.push_back(tracker_hit); + + } + + return true; +} + +void Tracker3DHitProcessor::finalize() { +} + +DECLARE_PROCESSOR(Tracker3DHitProcessor); diff --git a/processors/src/TrackingProcessor.cxx b/processors/src/TrackingProcessor.cxx index 6ed57fe96..cf2e722b9 100644 --- a/processors/src/TrackingProcessor.cxx +++ b/processors/src/TrackingProcessor.cxx @@ -11,7 +11,7 @@ TrackingProcessor::~TrackingProcessor() { void TrackingProcessor::initialize(TTree* tree) { tree->Branch(Collections::GBL_TRACKS, &tracks_); - tree->Branch(Collections::TRACKER_HITS, &hits_); + tree->Branch(Collections::TRACKER_HITS_ON_TRACK, &hits_); tree->Branch(Collections::RAW_SVT_HITS_ON_TRACK, &rawhits_); } From d284574efbe66e16b8fa9b5ccd4d3e861300fdf2 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Wed, 13 Nov 2019 13:58:38 -0500 Subject: [PATCH 170/314] The PySys_SetArgv must be called even when there are no arguments, to set the script name. --- processing/src/ConfigurePython.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/processing/src/ConfigurePython.cxx b/processing/src/ConfigurePython.cxx index 1a0b95eda..39d0f2219 100644 --- a/processing/src/ConfigurePython.cxx +++ b/processing/src/ConfigurePython.cxx @@ -55,7 +55,7 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], // Set the command line arguments passed to the python script to be // executed. Note that the first parameter in the list or arguments // should refer to the script to be executed. - if (nargs > 0) { + #if PY_MAJOR_VERSION >= 3 wchar_t** targs = new wchar_t*[nargs + 1]; @@ -86,7 +86,6 @@ ConfigurePython::ConfigurePython(const std::string& python_script, char* args[], PySys_SetArgvEx(nargs+1, targs, 1); delete[] targs; #endif - } PyObject* script = nullptr; PyObject* process = nullptr; From db6b637a5739a92b76ed522f23625d3b80153b43 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Butti Date: Wed, 13 Nov 2019 18:24:19 -0800 Subject: [PATCH 171/314] First commit for json configuration for plotting. Tested on track histos. --- analysis/include/HistoManager.h | 12 +- analysis/include/TrackHistos.h | 2 +- analysis/include/json.hpp | 22877 ++++++++++++++++ .../plotconfigs/tracking/basicTracking.json | 158 + analysis/src/HistoManager.cxx | 19 + analysis/src/TrackHistos.cxx | 324 +- processors/include/RefittedTracksProcessor.h | 4 +- processors/src/RefittedTracksProcessor.cxx | 22 +- 8 files changed, 23200 insertions(+), 218 deletions(-) create mode 100644 analysis/include/json.hpp create mode 100644 analysis/plotconfigs/tracking/basicTracking.json diff --git a/analysis/include/HistoManager.h b/analysis/include/HistoManager.h index 39ec4532a..d90d16a67 100644 --- a/analysis/include/HistoManager.h +++ b/analysis/include/HistoManager.h @@ -9,6 +9,10 @@ #include #include #include +#include "json.hpp" + +//for convenience +using json = nlohmann::json; class HistoManager { @@ -67,10 +71,14 @@ class HistoManager { virtual void Define2DHistos(){}; virtual void Define1DHistos(){}; + void Fill1DHisto(const std::string& histoName, float value, float weight=1.); + virtual void GetHistosFromFile(TFile* inFile, const std::string& name,const std::string& folder = ""); virtual void saveHistos(TFile* outF = nullptr,std::string folder = ""); - + + virtual void loadHistoConfig(const std::string histoConfigFile); + virtual void sumw2(); void debugMode(bool debug) {debug_ = debug;} @@ -91,7 +99,7 @@ class HistoManager { typedef std::map::iterator it3d; bool debug_{false}; - + json _h_configs; }; diff --git a/analysis/include/TrackHistos.h b/analysis/include/TrackHistos.h index 0b2856f3f..b6fc2b1b0 100644 --- a/analysis/include/TrackHistos.h +++ b/analysis/include/TrackHistos.h @@ -25,7 +25,7 @@ class TrackHistos : public HistoManager { void Fill1DHistograms(Track* track = nullptr, Vertex* vtx = nullptr, float weight = 1.); - void Fill1DHisto(const std::string& histoName, float value, float weight=1.); + //track_x goes for x axis, and y for y axis void FillTrackComparisonHistograms(Track* track_x, Track* track_y, float weight = 1.); diff --git a/analysis/include/json.hpp b/analysis/include/json.hpp new file mode 100644 index 000000000..726a96322 --- /dev/null +++ b/analysis/include/json.hpp @@ -0,0 +1,22877 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ +| | |__ | | | | | | version 3.7.2 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2013-2019 Niels Lohmann . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef INCLUDE_NLOHMANN_JSON_HPP_ +#define INCLUDE_NLOHMANN_JSON_HPP_ + +#define NLOHMANN_JSON_VERSION_MAJOR 3 +#define NLOHMANN_JSON_VERSION_MINOR 7 +#define NLOHMANN_JSON_VERSION_PATCH 2 + +#include // all_of, find, for_each +#include // assert +#include // and, not, or +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#include // istream, ostream +#include // random_access_iterator_tag +#include // unique_ptr +#include // accumulate +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap +#include // vector + +// #include + + +#include + +// #include + + +#include // transform +#include // array +#include // and, not +#include // forward_list +#include // inserter, front_inserter, end +#include // map +#include // string +#include // tuple, make_tuple +#include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +#include // unordered_map +#include // pair, declval +#include // valarray + +// #include + + +#include // exception +#include // runtime_error +#include // to_string + +// #include + + +#include // size_t + +namespace nlohmann +{ +namespace detail +{ +/// struct to capture the start position of the current token +struct position_t +{ + /// the total number of characters read + std::size_t chars_read_total = 0; + /// the number of characters read in the current line + std::size_t chars_read_current_line = 0; + /// the number of lines read + std::size_t lines_read = 0; + + /// conversion to size_t to preserve SAX interface + constexpr operator size_t() const + { + return chars_read_total; + } +}; + +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // pair +// #include +/* Hedley - https://nemequ.github.io/hedley + * Created by Evan Nemerson + * + * To the extent possible under law, the author(s) have dedicated all + * copyright and related and neighboring rights to this software to + * the public domain worldwide. This software is distributed without + * any warranty. + * + * For details, see . + * SPDX-License-Identifier: CC0-1.0 + */ + +#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 11) +#if defined(JSON_HEDLEY_VERSION) + #undef JSON_HEDLEY_VERSION +#endif +#define JSON_HEDLEY_VERSION 11 + +#if defined(JSON_HEDLEY_STRINGIFY_EX) + #undef JSON_HEDLEY_STRINGIFY_EX +#endif +#define JSON_HEDLEY_STRINGIFY_EX(x) #x + +#if defined(JSON_HEDLEY_STRINGIFY) + #undef JSON_HEDLEY_STRINGIFY +#endif +#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) + +#if defined(JSON_HEDLEY_CONCAT_EX) + #undef JSON_HEDLEY_CONCAT_EX +#endif +#define JSON_HEDLEY_CONCAT_EX(a,b) a##b + +#if defined(JSON_HEDLEY_CONCAT) + #undef JSON_HEDLEY_CONCAT +#endif +#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) + +#if defined(JSON_HEDLEY_VERSION_ENCODE) + #undef JSON_HEDLEY_VERSION_ENCODE +#endif +#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) + #undef JSON_HEDLEY_VERSION_DECODE_MAJOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) + #undef JSON_HEDLEY_VERSION_DECODE_MINOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) + #undef JSON_HEDLEY_VERSION_DECODE_REVISION +#endif +#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) + +#if defined(JSON_HEDLEY_GNUC_VERSION) + #undef JSON_HEDLEY_GNUC_VERSION +#endif +#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#elif defined(__GNUC__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) +#endif + +#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) + #undef JSON_HEDLEY_GNUC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GNUC_VERSION) + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION) + #undef JSON_HEDLEY_MSVC_VERSION +#endif +#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) +#elif defined(_MSC_FULL_VER) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) +#elif defined(_MSC_VER) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) + #undef JSON_HEDLEY_MSVC_VERSION_CHECK +#endif +#if !defined(_MSC_VER) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) +#elif defined(_MSC_VER) && (_MSC_VER >= 1200) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) +#else + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION) + #undef JSON_HEDLEY_INTEL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) +#elif defined(__INTEL_COMPILER) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_VERSION) + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION) + #undef JSON_HEDLEY_PGI_VERSION +#endif +#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) + #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) + #undef JSON_HEDLEY_PGI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #undef JSON_HEDLEY_SUNPRO_VERSION +#endif +#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) +#elif defined(__SUNPRO_C) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) +#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) +#elif defined(__SUNPRO_CC) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) + #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION +#endif +#if defined(__EMSCRIPTEN__) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION) + #undef JSON_HEDLEY_ARM_VERSION +#endif +#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) +#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) + #undef JSON_HEDLEY_ARM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_ARM_VERSION) + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION) + #undef JSON_HEDLEY_IBM_VERSION +#endif +#if defined(__ibmxl__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) +#elif defined(__xlC__) && defined(__xlC_ver__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) +#elif defined(__xlC__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) + #undef JSON_HEDLEY_IBM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IBM_VERSION) + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_VERSION) + #undef JSON_HEDLEY_TI_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) + #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_VERSION_CHECK) + #undef JSON_HEDLEY_TI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_VERSION) + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION) + #undef JSON_HEDLEY_CRAY_VERSION +#endif +#if defined(_CRAYC) + #if defined(_RELEASE_PATCHLEVEL) + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) + #else + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) + #undef JSON_HEDLEY_CRAY_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_CRAY_VERSION) + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION) + #undef JSON_HEDLEY_IAR_VERSION +#endif +#if defined(__IAR_SYSTEMS_ICC__) + #if __VER__ > 1000 + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) + #else + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(VER / 100, __VER__ % 100, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) + #undef JSON_HEDLEY_IAR_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IAR_VERSION) + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION) + #undef JSON_HEDLEY_TINYC_VERSION +#endif +#if defined(__TINYC__) + #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) + #undef JSON_HEDLEY_TINYC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION) + #undef JSON_HEDLEY_DMC_VERSION +#endif +#if defined(__DMC__) + #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) + #undef JSON_HEDLEY_DMC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_DMC_VERSION) + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #undef JSON_HEDLEY_COMPCERT_VERSION +#endif +#if defined(__COMPCERT_VERSION__) + #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) + #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION) + #undef JSON_HEDLEY_PELLES_VERSION +#endif +#if defined(__POCC__) + #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) + #undef JSON_HEDLEY_PELLES_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PELLES_VERSION) + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION) + #undef JSON_HEDLEY_GCC_VERSION +#endif +#if \ + defined(JSON_HEDLEY_GNUC_VERSION) && \ + !defined(__clang__) && \ + !defined(JSON_HEDLEY_INTEL_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_ARM_VERSION) && \ + !defined(JSON_HEDLEY_TI_VERSION) && \ + !defined(__COMPCERT__) + #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) __has_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE +#endif +#if \ + defined(__has_cpp_attribute) && \ + defined(__cplusplus) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS +#endif +#if !defined(__cplusplus) || !defined(__has_cpp_attribute) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#elif \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ + (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_BUILTIN) + #undef JSON_HEDLEY_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) +#else + #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) + #undef JSON_HEDLEY_GNUC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) + #undef JSON_HEDLEY_GCC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_FEATURE) + #undef JSON_HEDLEY_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) +#else + #define JSON_HEDLEY_HAS_FEATURE(feature) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) + #undef JSON_HEDLEY_GNUC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) + #undef JSON_HEDLEY_GCC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_EXTENSION) + #undef JSON_HEDLEY_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) +#else + #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) + #undef JSON_HEDLEY_GNUC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) + #undef JSON_HEDLEY_GCC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_WARNING) + #undef JSON_HEDLEY_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) +#else + #define JSON_HEDLEY_HAS_WARNING(warning) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) + #undef JSON_HEDLEY_GNUC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_WARNING) + #undef JSON_HEDLEY_GCC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ +#endif +#if defined(__cplusplus) && JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +#else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x +#endif + +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + defined(__clang__) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) + #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_PRAGMA(value) __pragma(value) +#else + #define JSON_HEDLEY_PRAGMA(value) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) + #undef JSON_HEDLEY_DIAGNOSTIC_PUSH +#endif +#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) + #undef JSON_HEDLEY_DIAGNOSTIC_POP +#endif +#if defined(__clang__) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) + #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) +#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_PUSH + #define JSON_HEDLEY_DIAGNOSTIC_POP +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") +#elif JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif + +#if defined(JSON_HEDLEY_DEPRECATED) + #undef JSON_HEDLEY_DEPRECATED +#endif +#if defined(JSON_HEDLEY_DEPRECATED_FOR) + #undef JSON_HEDLEY_DEPRECATED_FOR +#endif +#if defined(__cplusplus) && (__cplusplus >= 201402L) + #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) +#elif \ + JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,3,0) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") +#else + #define JSON_HEDLEY_DEPRECATED(since) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) +#endif + +#if defined(JSON_HEDLEY_UNAVAILABLE) + #undef JSON_HEDLEY_UNAVAILABLE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) +#else + #define JSON_HEDLEY_UNAVAILABLE(available_since) +#endif + +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT +#endif +#if defined(__cplusplus) && (__cplusplus >= 201703L) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) +#elif defined(_Check_return_) /* SAL */ + #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ +#else + #define JSON_HEDLEY_WARN_UNUSED_RESULT +#endif + +#if defined(JSON_HEDLEY_SENTINEL) + #undef JSON_HEDLEY_SENTINEL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) + #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) +#else + #define JSON_HEDLEY_SENTINEL(position) +#endif + +#if defined(JSON_HEDLEY_NO_RETURN) + #undef JSON_HEDLEY_NO_RETURN +#endif +#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NO_RETURN __noreturn +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define JSON_HEDLEY_NO_RETURN _Noreturn +#elif defined(__cplusplus) && (__cplusplus >= 201103L) + #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(18,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(17,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#else + #define JSON_HEDLEY_NO_RETURN +#endif + +#if defined(JSON_HEDLEY_NO_ESCAPE) + #undef JSON_HEDLEY_NO_ESCAPE +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) + #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) +#else + #define JSON_HEDLEY_NO_ESCAPE +#endif + +#if defined(JSON_HEDLEY_UNREACHABLE) + #undef JSON_HEDLEY_UNREACHABLE +#endif +#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #undef JSON_HEDLEY_UNREACHABLE_RETURN +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) + #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) + #define JSON_HEDLEY_UNREACHABLE() __assume(0) +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) + #if defined(__cplusplus) + #define JSON_HEDLEY_UNREACHABLE() std::_nassert(0) + #else + #define JSON_HEDLEY_UNREACHABLE() _nassert(0) + #endif + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value +#elif defined(EXIT_FAILURE) + #define JSON_HEDLEY_UNREACHABLE() abort() +#else + #define JSON_HEDLEY_UNREACHABLE() + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return value +#endif +#if !defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() +#endif + +#if defined(JSON_HEDLEY_ASSUME) + #undef JSON_HEDLEY_ASSUME +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_ASSUME(expr) __assume(expr) +#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) + #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) + #if defined(__cplusplus) + #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) + #else + #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #endif +#elif \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && !defined(JSON_HEDLEY_ARM_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) + #define JSON_HEDLEY_ASSUME(expr) ((void) ((expr) ? 1 : (__builtin_unreachable(), 1))) +#else + #define JSON_HEDLEY_ASSUME(expr) ((void) (expr)) +#endif + +JSON_HEDLEY_DIAGNOSTIC_PUSH +#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") + #pragma clang diagnostic ignored "-Wpedantic" +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) + #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" +#endif +#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) + #if defined(__clang__) + #pragma clang diagnostic ignored "-Wvariadic-macros" + #elif defined(JSON_HEDLEY_GCC_VERSION) + #pragma GCC diagnostic ignored "-Wvariadic-macros" + #endif +#endif +#if defined(JSON_HEDLEY_NON_NULL) + #undef JSON_HEDLEY_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) +#else + #define JSON_HEDLEY_NON_NULL(...) +#endif +JSON_HEDLEY_DIAGNOSTIC_POP + +#if defined(JSON_HEDLEY_PRINTF_FORMAT) + #undef JSON_HEDLEY_PRINTF_FORMAT +#endif +#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) +#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) +#else + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) +#endif + +#if defined(JSON_HEDLEY_CONSTEXPR) + #undef JSON_HEDLEY_CONSTEXPR +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #endif +#endif +#if !defined(JSON_HEDLEY_CONSTEXPR) + #define JSON_HEDLEY_CONSTEXPR +#endif + +#if defined(JSON_HEDLEY_PREDICT) + #undef JSON_HEDLEY_PREDICT +#endif +#if defined(JSON_HEDLEY_LIKELY) + #undef JSON_HEDLEY_LIKELY +#endif +#if defined(JSON_HEDLEY_UNLIKELY) + #undef JSON_HEDLEY_UNLIKELY +#endif +#if defined(JSON_HEDLEY_UNPREDICTABLE) + #undef JSON_HEDLEY_UNPREDICTABLE +#endif +#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) + #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable(!!(expr)) +#endif +#if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) +# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability(expr, value, probability) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1, probability) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, probability) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#if !defined(JSON_HEDLEY_BUILTIN_UNPREDICTABLE) + #define JSON_HEDLEY_BUILTIN_UNPREDICTABLE(expr) __builtin_expect_with_probability(!!(expr), 1, 0.5) +#endif +#elif \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) +# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ + (((probability) >= 0.9) ? __builtin_expect(!!(expr), (expected)) : (((void) (expected)), !!(expr))) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ + (__extension__ ({ \ + JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ + })) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ + (__extension__ ({ \ + JSON_HEDLEY_CONSTEXPR double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ + })) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#else +# define JSON_HEDLEY_PREDICT(expr, expected, probability) (((void) (expected)), !!(expr)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) +# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) +#endif +#if !defined(JSON_HEDLEY_UNPREDICTABLE) + #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) +#endif + +#if defined(JSON_HEDLEY_MALLOC) + #undef JSON_HEDLEY_MALLOC +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) + #define JSON_HEDLEY_MALLOC __declspec(restrict) +#else + #define JSON_HEDLEY_MALLOC +#endif + +#if defined(JSON_HEDLEY_PURE) + #undef JSON_HEDLEY_PURE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_PURE __attribute__((__pure__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") +#else + #define JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_CONST) + #undef JSON_HEDLEY_CONST +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_CONST __attribute__((__const__)) +#elif \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_CONST _Pragma("no_side_effect") +#else + #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_RESTRICT) + #undef JSON_HEDLEY_RESTRICT +#endif +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT restrict +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + defined(__clang__) + #define JSON_HEDLEY_RESTRICT __restrict +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT _Restrict +#else + #define JSON_HEDLEY_RESTRICT +#endif + +#if defined(JSON_HEDLEY_INLINE) + #undef JSON_HEDLEY_INLINE +#endif +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define JSON_HEDLEY_INLINE inline +#elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) + #define JSON_HEDLEY_INLINE __inline__ +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_INLINE __inline +#else + #define JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_ALWAYS_INLINE) + #undef JSON_HEDLEY_ALWAYS_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) + #define JSON_HEDLEY_ALWAYS_INLINE __forceinline +#elif JSON_HEDLEY_TI_VERSION_CHECK(7,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") +#else + #define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_NEVER_INLINE) + #undef JSON_HEDLEY_NEVER_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") +#elif JSON_HEDLEY_TI_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#else + #define JSON_HEDLEY_NEVER_INLINE +#endif + +#if defined(JSON_HEDLEY_PRIVATE) + #undef JSON_HEDLEY_PRIVATE +#endif +#if defined(JSON_HEDLEY_PUBLIC) + #undef JSON_HEDLEY_PUBLIC +#endif +#if defined(JSON_HEDLEY_IMPORT) + #undef JSON_HEDLEY_IMPORT +#endif +#if defined(_WIN32) || defined(__CYGWIN__) + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC __declspec(dllexport) + #define JSON_HEDLEY_IMPORT __declspec(dllimport) +#else + #if \ + JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_TI_VERSION_CHECK(7,3,0) && defined(__TI_EABI__) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) + #define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) + #define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) + #else + #define JSON_HEDLEY_PRIVATE + #define JSON_HEDLEY_PUBLIC + #endif + #define JSON_HEDLEY_IMPORT extern +#endif + +#if defined(JSON_HEDLEY_NO_THROW) + #undef JSON_HEDLEY_NO_THROW +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NO_THROW __declspec(nothrow) +#else + #define JSON_HEDLEY_NO_THROW +#endif + +#if defined(JSON_HEDLEY_FALL_THROUGH) + #undef JSON_HEDLEY_FALL_THROUGH +#endif +#if JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(fallthrough,7,0,0) && !defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) +#elif defined(__fallthrough) /* SAL */ + #define JSON_HEDLEY_FALL_THROUGH __fallthrough +#else + #define JSON_HEDLEY_FALL_THROUGH +#endif + +#if defined(JSON_HEDLEY_RETURNS_NON_NULL) + #undef JSON_HEDLEY_RETURNS_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) +#elif defined(_Ret_notnull_) /* SAL */ + #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ +#else + #define JSON_HEDLEY_RETURNS_NON_NULL +#endif + +#if defined(JSON_HEDLEY_ARRAY_PARAM) + #undef JSON_HEDLEY_ARRAY_PARAM +#endif +#if \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(__STDC_NO_VLA__) && \ + !defined(__cplusplus) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_ARRAY_PARAM(name) (name) +#else + #define JSON_HEDLEY_ARRAY_PARAM(name) +#endif + +#if defined(JSON_HEDLEY_IS_CONSTANT) + #undef JSON_HEDLEY_IS_CONSTANT +#endif +#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) + #undef JSON_HEDLEY_REQUIRE_CONSTEXPR +#endif +/* JSON_HEDLEY_IS_CONSTEXPR_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #undef JSON_HEDLEY_IS_CONSTEXPR_ +#endif +#if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(6,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) + #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) +#endif +#if !defined(__cplusplus) +# if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) +#endif +# elif \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(JSON_HEDLEY_SUNPRO_VERSION) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) +#endif +# elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + defined(JSON_HEDLEY_INTEL_VERSION) || \ + defined(JSON_HEDLEY_TINYC_VERSION) || \ + defined(JSON_HEDLEY_TI_VERSION) || \ + defined(__clang__) +# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ + sizeof(void) != \ + sizeof(*( \ + 1 ? \ + ((void*) ((expr) * 0L) ) : \ +((struct { char v[sizeof(void) * 2]; } *) 1) \ + ) \ + ) \ + ) +# endif +#endif +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) +#else + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) +#endif + +#if defined(JSON_HEDLEY_BEGIN_C_DECLS) + #undef JSON_HEDLEY_BEGIN_C_DECLS +#endif +#if defined(JSON_HEDLEY_END_C_DECLS) + #undef JSON_HEDLEY_END_C_DECLS +#endif +#if defined(JSON_HEDLEY_C_DECL) + #undef JSON_HEDLEY_C_DECL +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { + #define JSON_HEDLEY_END_C_DECLS } + #define JSON_HEDLEY_C_DECL extern "C" +#else + #define JSON_HEDLEY_BEGIN_C_DECLS + #define JSON_HEDLEY_END_C_DECLS + #define JSON_HEDLEY_C_DECL +#endif + +#if defined(JSON_HEDLEY_STATIC_ASSERT) + #undef JSON_HEDLEY_STATIC_ASSERT +#endif +#if \ + !defined(__cplusplus) && ( \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ + JSON_HEDLEY_HAS_FEATURE(c_static_assert) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + defined(_Static_assert) \ + ) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) +#elif \ + (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ + (defined(__cplusplus) && JSON_HEDLEY_TI_VERSION_CHECK(8,3,0)) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) +#else +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) +#endif + +#if defined(JSON_HEDLEY_CONST_CAST) + #undef JSON_HEDLEY_CONST_CAST +#endif +#if defined(__cplusplus) +# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast(expr)) +#elif \ + JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_REINTERPRET_CAST) + #undef JSON_HEDLEY_REINTERPRET_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast(expr)) +#else + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (*((T*) &(expr))) +#endif + +#if defined(JSON_HEDLEY_STATIC_CAST) + #undef JSON_HEDLEY_STATIC_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast(expr)) +#else + #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_CPP_CAST) + #undef JSON_HEDLEY_CPP_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_CPP_CAST(T, expr) static_cast(expr) +#else + #define JSON_HEDLEY_CPP_CAST(T, expr) (expr) +#endif + +#if defined(JSON_HEDLEY_NULL) + #undef JSON_HEDLEY_NULL +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #elif defined(NULL) + #define JSON_HEDLEY_NULL NULL + #else + #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #endif +#elif defined(NULL) + #define JSON_HEDLEY_NULL NULL +#else + #define JSON_HEDLEY_NULL ((void*) 0) +#endif + +#if defined(JSON_HEDLEY_MESSAGE) + #undef JSON_HEDLEY_MESSAGE +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_MESSAGE(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(message msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) +#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_WARNING) + #undef JSON_HEDLEY_WARNING +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_WARNING(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(clang warning msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_REQUIRE) + #undef JSON_HEDLEY_REQUIRE +#endif +#if defined(JSON_HEDLEY_REQUIRE_MSG) + #undef JSON_HEDLEY_REQUIRE_MSG +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) +# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") +# define JSON_HEDLEY_REQUIRE(expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), #expr, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), msg, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) +# endif +#else +# define JSON_HEDLEY_REQUIRE(expr) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) +#endif + +#if defined(JSON_HEDLEY_FLAGS) + #undef JSON_HEDLEY_FLAGS +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) + #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) +#endif + +#if defined(JSON_HEDLEY_FLAGS_CAST) + #undef JSON_HEDLEY_FLAGS_CAST +#endif +#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) +# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("warning(disable:188)") \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) +#endif + +#if defined(JSON_HEDLEY_EMPTY_BASES) + #undef JSON_HEDLEY_EMPTY_BASES +#endif +#if JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0) + #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) +#else + #define JSON_HEDLEY_EMPTY_BASES +#endif + +/* Remaining macros are deprecated. */ + +#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK +#endif +#if defined(__clang__) + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) +#else + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) + #undef JSON_HEDLEY_CLANG_HAS_BUILTIN +#endif +#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) + +#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) + #undef JSON_HEDLEY_CLANG_HAS_FEATURE +#endif +#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) + +#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) + #undef JSON_HEDLEY_CLANG_HAS_EXTENSION +#endif +#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) + +#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) + #undef JSON_HEDLEY_CLANG_HAS_WARNING +#endif +#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) + +#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ + + +// This file contains all internal macro definitions +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// C++ language standard detection +#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 +#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 +#endif + +// disable float-equal warnings on GCC/clang +#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdocumentation" +#endif + +// allow to disable exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #include + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [&j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + + +namespace nlohmann +{ +namespace detail +{ +//////////////// +// exceptions // +//////////////// + +/*! +@brief general exception of the @ref basic_json class + +This class is an extension of `std::exception` objects with a member @a id for +exception ids. It is used as the base class for all exceptions thrown by the +@ref basic_json class. This class can hence be used as "wildcard" to catch +exceptions. + +Subclasses: +- @ref parse_error for exceptions indicating a parse error +- @ref invalid_iterator for exceptions indicating errors with iterators +- @ref type_error for exceptions indicating executing a member function with + a wrong type +- @ref out_of_range for exceptions indicating access out of the defined range +- @ref other_error for exceptions indicating other library errors + +@internal +@note To have nothrow-copy-constructible exceptions, we internally use + `std::runtime_error` which can cope with arbitrary-length error messages. + Intermediate strings are built with static functions and then passed to + the actual constructor. +@endinternal + +@liveexample{The following code shows how arbitrary library exceptions can be +caught.,exception} + +@since version 3.0.0 +*/ +class exception : public std::exception +{ + public: + /// returns the explanatory string + JSON_HEDLEY_RETURNS_NON_NULL + const char* what() const noexcept override + { + return m.what(); + } + + /// the id of the exception + const int id; + + protected: + JSON_HEDLEY_NON_NULL(3) + exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} + + static std::string name(const std::string& ename, int id_) + { + return "[json.exception." + ename + "." + std::to_string(id_) + "] "; + } + + private: + /// an exception object as storage for error messages + std::runtime_error m; +}; + +/*! +@brief exception indicating a parse error + +This exception is thrown by the library when a parse error occurs. Parse errors +can occur during the deserialization of JSON text, CBOR, MessagePack, as well +as when using JSON Patch. + +Member @a byte holds the byte index of the last read character in the input +file. + +Exceptions have ids 1xx. + +name / id | example message | description +------------------------------ | --------------- | ------------------------- +json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position. +json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. +json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid. +json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects. +json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. +json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`. +json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character. +json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape sequences. +json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number. +json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. +json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. +json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read. +json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F | The parsing of the corresponding BSON record type is not implemented (yet). + +@note For an input with n bytes, 1 is the index of the first character and n+1 + is the index of the terminating null byte or the end of file. This also + holds true when reading a byte vector (CBOR or MessagePack). + +@liveexample{The following code shows how a `parse_error` exception can be +caught.,parse_error} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class parse_error : public exception +{ + public: + /*! + @brief create a parse error exception + @param[in] id_ the id of the exception + @param[in] pos the position where the error occurred (or with + chars_read_total=0 if the position cannot be + determined) + @param[in] what_arg the explanatory string + @return parse_error object + */ + static parse_error create(int id_, const position_t& pos, const std::string& what_arg) + { + std::string w = exception::name("parse_error", id_) + "parse error" + + position_string(pos) + ": " + what_arg; + return parse_error(id_, pos.chars_read_total, w.c_str()); + } + + static parse_error create(int id_, std::size_t byte_, const std::string& what_arg) + { + std::string w = exception::name("parse_error", id_) + "parse error" + + (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + + ": " + what_arg; + return parse_error(id_, byte_, w.c_str()); + } + + /*! + @brief byte index of the parse error + + The byte index of the last read character in the input file. + + @note For an input with n bytes, 1 is the index of the first character and + n+1 is the index of the terminating null byte or the end of file. + This also holds true when reading a byte vector (CBOR or MessagePack). + */ + const std::size_t byte; + + private: + parse_error(int id_, std::size_t byte_, const char* what_arg) + : exception(id_, what_arg), byte(byte_) {} + + static std::string position_string(const position_t& pos) + { + return " at line " + std::to_string(pos.lines_read + 1) + + ", column " + std::to_string(pos.chars_read_current_line); + } +}; + +/*! +@brief exception indicating errors with iterators + +This exception is thrown if iterators passed to a library function do not match +the expected semantics. + +Exceptions have ids 2xx. + +name / id | example message | description +----------------------------------- | --------------- | ------------------------- +json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. +json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. +json.exception.invalid_iterator.203 | iterators do not fit current value | Either iterator passed to function @ref erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from. +json.exception.invalid_iterator.204 | iterators out of range | When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (@ref begin(), @ref end()), because this is the only way the single stored value is expressed. All other ranges are invalid. +json.exception.invalid_iterator.205 | iterator out of range | When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the @ref begin() iterator, because it is the only way to address the stored value. All other iterators are invalid. +json.exception.invalid_iterator.206 | cannot construct with iterators from null | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range. +json.exception.invalid_iterator.207 | cannot use key() for non-object iterators | The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key. +json.exception.invalid_iterator.208 | cannot use operator[] for object iterators | The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. +json.exception.invalid_iterator.209 | cannot use offsets with object iterators | The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. +json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. +json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to. +json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container. +json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered. +json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to @ref begin(). + +@liveexample{The following code shows how an `invalid_iterator` exception can be +caught.,invalid_iterator} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class invalid_iterator : public exception +{ + public: + static invalid_iterator create(int id_, const std::string& what_arg) + { + std::string w = exception::name("invalid_iterator", id_) + what_arg; + return invalid_iterator(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + invalid_iterator(int id_, const char* what_arg) + : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating executing a member function with a wrong type + +This exception is thrown in case of a type error; that is, a library function is +executed on a JSON value whose type does not match the expected semantics. + +Exceptions have ids 3xx. + +name / id | example message | description +----------------------------- | --------------- | ------------------------- +json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead. +json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types. +json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual type is object | To retrieve a reference to a value stored in a @ref basic_json object with @ref get_ref, the type of the reference must match the value type. For instance, for a JSON array, the @a ReferenceType must be @ref array_t &. +json.exception.type_error.304 | cannot use at() with string | The @ref at() member functions can only be executed for certain JSON types. +json.exception.type_error.305 | cannot use operator[] with string | The @ref operator[] member functions can only be executed for certain JSON types. +json.exception.type_error.306 | cannot use value() with string | The @ref value() member functions can only be executed for certain JSON types. +json.exception.type_error.307 | cannot use erase() with string | The @ref erase() member functions can only be executed for certain JSON types. +json.exception.type_error.308 | cannot use push_back() with string | The @ref push_back() and @ref operator+= member functions can only be executed for certain JSON types. +json.exception.type_error.309 | cannot use insert() with | The @ref insert() member functions can only be executed for certain JSON types. +json.exception.type_error.310 | cannot use swap() with number | The @ref swap() member functions can only be executed for certain JSON types. +json.exception.type_error.311 | cannot use emplace_back() with string | The @ref emplace_back() member function can only be executed for certain JSON types. +json.exception.type_error.312 | cannot use update() with string | The @ref update() member functions can only be executed for certain JSON types. +json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined. +json.exception.type_error.314 | only objects can be unflattened | The @ref unflatten function only works for an object whose keys are JSON Pointers. +json.exception.type_error.315 | values in object must be primitive | The @ref unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive. +json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref dump function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. | +json.exception.type_error.317 | JSON value cannot be serialized to requested format | The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw `true` or `null` JSON object cannot be serialized to BSON) | + +@liveexample{The following code shows how a `type_error` exception can be +caught.,type_error} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class type_error : public exception +{ + public: + static type_error create(int id_, const std::string& what_arg) + { + std::string w = exception::name("type_error", id_) + what_arg; + return type_error(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating access out of the defined range + +This exception is thrown in case a library function is called on an input +parameter that exceeds the expected range, for instance in case of array +indices or nonexisting object keys. + +Exceptions have ids 4xx. + +name / id | example message | description +------------------------------- | --------------- | ------------------------- +json.exception.out_of_range.401 | array index 3 is out of range | The provided array index @a i is larger than @a size-1. +json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it. +json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object. +json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved. +json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. +json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. +json.exception.out_of_range.407 | number overflow serializing '9223372036854775808' | UBJSON and BSON only support integer numbers up to 9223372036854775807. | +json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | The size (following `#`) of an UBJSON array or object exceeds the maximal capacity. | +json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string | + +@liveexample{The following code shows how an `out_of_range` exception can be +caught.,out_of_range} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class out_of_range : public exception +{ + public: + static out_of_range create(int id_, const std::string& what_arg) + { + std::string w = exception::name("out_of_range", id_) + what_arg; + return out_of_range(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating other library errors + +This exception is thrown in case of errors that cannot be classified with the +other exception types. + +Exceptions have ids 5xx. + +name / id | example message | description +------------------------------ | --------------- | ------------------------- +json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed. + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range + +@liveexample{The following code shows how an `other_error` exception can be +caught.,other_error} + +@since version 3.0.0 +*/ +class other_error : public exception +{ + public: + static other_error create(int id_, const std::string& what_arg) + { + std::string w = exception::name("other_error", id_) + what_arg; + return other_error(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +#include // not +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type + +namespace nlohmann +{ +namespace detail +{ +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +template +using uncvref_t = typename std::remove_cv::type>::type; + +// implementation of C++14 index_sequence and affiliates +// source: https://stackoverflow.com/a/32223343 +template +struct index_sequence +{ + using type = index_sequence; + using value_type = std::size_t; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +template +struct merge_and_renumber; + +template +struct merge_and_renumber, index_sequence> + : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; + +template +struct make_index_sequence + : merge_and_renumber < typename make_index_sequence < N / 2 >::type, + typename make_index_sequence < N - N / 2 >::type > {}; + +template<> struct make_index_sequence<0> : index_sequence<> {}; +template<> struct make_index_sequence<1> : index_sequence<0> {}; + +template +using index_sequence_for = make_index_sequence; + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static constexpr T value{}; +}; + +template +constexpr T static_const::value; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // not +#include // numeric_limits +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval + +// #include + + +#include // random_access_iterator_tag + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; +} // namespace detail +} // namespace nlohmann + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template +struct iterator_types {}; + +template +struct iterator_types < + It, + void_t> +{ + using difference_type = typename It::difference_type; + using value_type = typename It::value_type; + using pointer = typename It::pointer; + using reference = typename It::reference; + using iterator_category = typename It::iterator_category; +}; + +// This is required as some compilers implement std::iterator_traits in a way that +// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. +template +struct iterator_traits +{ +}; + +template +struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> + : iterator_types +{ +}; + +template +struct iterator_traits::value>> +{ + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + +// #include + + +#include + +// #include + + +// http://en.cppreference.com/w/cpp/experimental/is_detected +namespace nlohmann +{ +namespace detail +{ +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template