From 685d4e4413cdc1bde1889e319601ddddfbb6dade Mon Sep 17 00:00:00 2001 From: drinkingkazu Date: Mon, 23 Oct 2017 12:10:54 -0500 Subject: [PATCH] 1st push, inheriting lots from uboonecode where this had been developed --- .gitignore | 45 ++ ImageMetaFromConfig.cxx | 44 ++ ImageMetaFromConfig.h | 53 ++ ImageMetaMaker.cxx | 47 ++ ImageMetaMaker.h | 66 +++ ImageMetaMakerBase.cxx | 19 + ImageMetaMakerBase.h | 56 ++ ImageMetaMakerFactory.cxx | 39 ++ ImageMetaMakerFactory.h | 11 + LAr2Image.cxx | 424 +++++++++++++++ LAr2Image.h | 76 +++ LArCVMetaData.h | 80 +++ LArCVMetaMaker.h | 68 +++ LArCVMetaMaker_service.cc | 225 ++++++++ LArCVSuperaDriver.cxx | 98 ++++ LArCVSuperaDriver.h | 90 +++ LArSoftSuperaDriver_module.cc | 284 ++++++++++ LinkDef.h | 53 ++ ParamsChStatus.cxx | 13 + ParamsChStatus.h | 53 ++ ParamsImage2D.cxx | 13 + ParamsImage2D.h | 52 ++ ParamsPixel2D.cxx | 13 + ParamsPixel2D.h | 53 ++ ParamsROI.cxx | 13 + ParamsROI.h | 53 ++ ParamsVoxel3D.cxx | 13 + ParamsVoxel3D.h | 53 ++ PulledPork3DSlicer.cxx | 389 +++++++++++++ PulledPork3DSlicer.h | 93 ++++ RSEFilter_module.cc | 76 +++ Range.cxx | 7 + Range.h | 145 +++++ SuperaBase.cxx | 143 +++++ SuperaBase.h | 140 +++++ SuperaCSVReader.h | 66 +++ SuperaChStatus.cxx | 65 +++ SuperaChStatus.h | 75 +++ SuperaHit.cxx | 72 +++ SuperaHit.h | 72 +++ SuperaMetaMaker.cxx | 74 +++ SuperaMetaMaker.h | 70 +++ SuperaOpDigit.cxx | 75 +++ SuperaOpDigit.h | 69 +++ SuperaTypes.cxx | 14 + SuperaTypes.h | 65 +++ SuperaWire.cxx | 73 +++ SuperaWire.h | 71 +++ VPlaneHandler_module.cc | 274 ++++++++++ WireRange3D.cxx | 362 +++++++++++++ WireRange3D.h | 159 ++++++ arxiv/MCOriginTree.cxx | 511 ++++++++++++++++++ arxiv/MCOriginTree.h | 154 ++++++ arxiv/MCParticleHelper.cxx | 455 ++++++++++++++++ arxiv/MCParticleHelper.h | 82 +++ arxiv/MCParticleTree.cxx | 355 ++++++++++++ arxiv/MCParticleTree.h | 145 +++++ arxiv/SuperaKeyPointCluster.cxx | 247 +++++++++ arxiv/SuperaKeyPointCluster.h | 88 +++ arxiv/SuperaMCPCluster.cxx | 143 +++++ arxiv/SuperaMCPCluster.h | 66 +++ arxiv/SuperaMCROI.cxx | 480 ++++++++++++++++ arxiv/SuperaMCROI.h | 114 ++++ arxiv/SuperaSimCh.cxx | 116 ++++ arxiv/SuperaSimCh.h | 72 +++ arxiv/SuperaSimVoxel3D.cxx | 141 +++++ arxiv/SuperaSimVoxel3D.h | 74 +++ example_drivers/README | 5 + example_drivers/dldata_larlite_supera.fcl | 62 +++ .../dldata_larlite_supera_calmod.fcl | 68 +++ .../dlmc_bnb_nu_larlite_supera.fcl | 125 +++++ .../project_supera_bnb_nu_foroverlay.xml | 57 ++ .../project_supera_extunbiased.xml | 59 ++ example_drivers/supera_basic.fcl | 61 +++ example_drivers/supera_basic_calmod.fcl | 62 +++ example_drivers/supera_example_calmod.fcl | 62 +++ example_drivers/supera_mcexample_calmod.fcl | 111 ++++ example_drivers/supera_segment_calmod.fcl | 111 ++++ experiments/uboone/CMakeLists.txt | 111 ++++ experiments/uboone/FMWKInterface.cxx | 176 ++++++ experiments/uboone/FMWKInterface.h | 115 ++++ ignore/dldata_larlite_supera_calmod.fcl | 81 +++ ignore/mc_segment_supera.fcl | 73 +++ ignore/test_supera.fcl | 77 +++ larlite/FMWKInterface.cxx | 140 +++++ larlite/FMWKInterface.h | 123 +++++ larlite/GNUmakefile | 30 + larlite/LArLiteSuperaDriver.cxx | 143 +++++ larlite/LArLiteSuperaDriver.h | 68 +++ mc_segment_supera.fcl | 73 +++ setup.sh | 20 + supera.py | 66 +++ supera_basic.fcl | 61 +++ supera_basic_calmod.fcl | 61 +++ supera_basic_focused.fcl | 72 +++ supera_michel_focused.fcl | 58 ++ supera_michel_mc_focused.fcl | 73 +++ supera_segment.fcl | 104 ++++ supera_segment_focused.fcl | 116 ++++ supera_segment_focused_plus.fcl | 198 +++++++ supera_segment_pork3d.fcl | 128 +++++ test_supera.fcl | 77 +++ 102 files changed, 11026 insertions(+) create mode 100644 .gitignore create mode 100644 ImageMetaFromConfig.cxx create mode 100644 ImageMetaFromConfig.h create mode 100644 ImageMetaMaker.cxx create mode 100644 ImageMetaMaker.h create mode 100644 ImageMetaMakerBase.cxx create mode 100644 ImageMetaMakerBase.h create mode 100644 ImageMetaMakerFactory.cxx create mode 100644 ImageMetaMakerFactory.h create mode 100644 LAr2Image.cxx create mode 100644 LAr2Image.h create mode 100644 LArCVMetaData.h create mode 100644 LArCVMetaMaker.h create mode 100644 LArCVMetaMaker_service.cc create mode 100644 LArCVSuperaDriver.cxx create mode 100644 LArCVSuperaDriver.h create mode 100644 LArSoftSuperaDriver_module.cc create mode 100644 LinkDef.h create mode 100644 ParamsChStatus.cxx create mode 100644 ParamsChStatus.h create mode 100644 ParamsImage2D.cxx create mode 100644 ParamsImage2D.h create mode 100644 ParamsPixel2D.cxx create mode 100644 ParamsPixel2D.h create mode 100644 ParamsROI.cxx create mode 100644 ParamsROI.h create mode 100644 ParamsVoxel3D.cxx create mode 100644 ParamsVoxel3D.h create mode 100644 PulledPork3DSlicer.cxx create mode 100644 PulledPork3DSlicer.h create mode 100644 RSEFilter_module.cc create mode 100644 Range.cxx create mode 100644 Range.h create mode 100644 SuperaBase.cxx create mode 100644 SuperaBase.h create mode 100644 SuperaCSVReader.h create mode 100644 SuperaChStatus.cxx create mode 100644 SuperaChStatus.h create mode 100644 SuperaHit.cxx create mode 100644 SuperaHit.h create mode 100644 SuperaMetaMaker.cxx create mode 100644 SuperaMetaMaker.h create mode 100644 SuperaOpDigit.cxx create mode 100644 SuperaOpDigit.h create mode 100644 SuperaTypes.cxx create mode 100644 SuperaTypes.h create mode 100644 SuperaWire.cxx create mode 100644 SuperaWire.h create mode 100644 VPlaneHandler_module.cc create mode 100644 WireRange3D.cxx create mode 100644 WireRange3D.h create mode 100644 arxiv/MCOriginTree.cxx create mode 100644 arxiv/MCOriginTree.h create mode 100644 arxiv/MCParticleHelper.cxx create mode 100644 arxiv/MCParticleHelper.h create mode 100644 arxiv/MCParticleTree.cxx create mode 100644 arxiv/MCParticleTree.h create mode 100644 arxiv/SuperaKeyPointCluster.cxx create mode 100644 arxiv/SuperaKeyPointCluster.h create mode 100644 arxiv/SuperaMCPCluster.cxx create mode 100644 arxiv/SuperaMCPCluster.h create mode 100644 arxiv/SuperaMCROI.cxx create mode 100644 arxiv/SuperaMCROI.h create mode 100644 arxiv/SuperaSimCh.cxx create mode 100644 arxiv/SuperaSimCh.h create mode 100644 arxiv/SuperaSimVoxel3D.cxx create mode 100644 arxiv/SuperaSimVoxel3D.h create mode 100644 example_drivers/README create mode 100644 example_drivers/dldata_larlite_supera.fcl create mode 100644 example_drivers/dldata_larlite_supera_calmod.fcl create mode 100644 example_drivers/dlmc_bnb_nu_larlite_supera.fcl create mode 100644 example_drivers/project_supera_bnb_nu_foroverlay.xml create mode 100644 example_drivers/project_supera_extunbiased.xml create mode 100644 example_drivers/supera_basic.fcl create mode 100644 example_drivers/supera_basic_calmod.fcl create mode 100644 example_drivers/supera_example_calmod.fcl create mode 100644 example_drivers/supera_mcexample_calmod.fcl create mode 100644 example_drivers/supera_segment_calmod.fcl create mode 100644 experiments/uboone/CMakeLists.txt create mode 100644 experiments/uboone/FMWKInterface.cxx create mode 100644 experiments/uboone/FMWKInterface.h create mode 100644 ignore/dldata_larlite_supera_calmod.fcl create mode 100644 ignore/mc_segment_supera.fcl create mode 100644 ignore/test_supera.fcl create mode 100644 larlite/FMWKInterface.cxx create mode 100644 larlite/FMWKInterface.h create mode 100644 larlite/GNUmakefile create mode 100644 larlite/LArLiteSuperaDriver.cxx create mode 100644 larlite/LArLiteSuperaDriver.h create mode 100644 mc_segment_supera.fcl create mode 100644 setup.sh create mode 100755 supera.py create mode 100644 supera_basic.fcl create mode 100644 supera_basic_calmod.fcl create mode 100644 supera_basic_focused.fcl create mode 100644 supera_michel_focused.fcl create mode 100644 supera_michel_mc_focused.fcl create mode 100644 supera_segment.fcl create mode 100644 supera_segment_focused.fcl create mode 100644 supera_segment_focused_plus.fcl create mode 100644 supera_segment_pork3d.fcl create mode 100644 test_supera.fcl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca87147 --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +*.out +*.depend +*.png +*.jpg +*.jpeg +*.pcm +*cmake +*CMakeFiles +*Dict.cxx +*Dict.h +*Dict.cc +*Cint.cxx +*Cint.h +*Cint.cc +*.root +*.json +*.db +*.log +*.dat +CMakeLists.txt +!experiments/*/CMakeLists.txt +FMWKInterface.* +*.txt +*.bin +*.root +build +app/PlayGround/* +app/Supera/APILArLite/Cropper.* +app/Supera/APILArLite/MCParticleTree.* +app/Supera/APILArLite/SuperaTypes.h +app/Supera/APILArLite/SuperaUtils.* +app/Supera/APILArLite/SuperaCore.* +app/Supera/APILArSoft/Cropper.* +app/Supera/APILArSoft/MCParticleTree.* +app/Supera/APILArSoft/SuperaTypes.h +app/Supera/APILArSoft/SuperaUtils.* +app/Supera/APILArSoft/SuperaCore.* +app/Supera/APILArSoft/supera.fcl +*~ +*.pyc +.ipynb_checkpoints +*.ipynb +.DS_Store +*.pdf +*.o diff --git a/ImageMetaFromConfig.cxx b/ImageMetaFromConfig.cxx new file mode 100644 index 0000000..a9de80d --- /dev/null +++ b/ImageMetaFromConfig.cxx @@ -0,0 +1,44 @@ +#ifndef __IMAGEMETAFROMCONFIG_CXX__ +#define __IMAGEMETAFROMCONFIG_CXX__ + +#include "ImageMetaFromConfig.h" + +namespace supera { + + void ImageMetaFromConfig::configure(const supera::Config_t& cfg) + { + ImageMetaMakerBase::configure(cfg); + auto min_time = cfg.get("MinTime"); + auto min_wire = cfg.get("MinWire"); + auto image_rows = cfg.get >("EventImageRows"); + auto image_cols = cfg.get >("EventImageCols"); + + auto const& comp_rows = RowCompressionFactor(); + auto const& comp_cols = ColCompressionFactor(); + + if(image_rows.size() != comp_rows.size()) { + std::cerr << "EventImageRows size != EventCompRows..." << std::endl; + throw std::exception(); + } + + if(image_rows.size() != image_cols.size()) { + std::cerr << "EventImageRows size != EventImageCols..." << std::endl; + throw std::exception(); + } + + // construct meta + for(size_t plane=0; plane& Meta() const + { return _meta_v; } + + private: + + std::vector _meta_v; + + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/ImageMetaMaker.cxx b/ImageMetaMaker.cxx new file mode 100644 index 0000000..ac18548 --- /dev/null +++ b/ImageMetaMaker.cxx @@ -0,0 +1,47 @@ +#ifndef IMAGEMETAMAKER_CXX +#define IMAGEMETAMAKER_CXX + +#include "ImageMetaMaker.h" +#include "ImageMetaMakerFactory.h" +namespace supera { + + ImageMetaMakerBase* ImageMetaMaker::_shared_meta_maker = nullptr; + + void ImageMetaMaker::configure(const supera::Config_t& cfg) + { + if(_meta_maker) { delete _meta_maker; } + _meta_maker = supera::CreateImageMetaMaker(cfg); + } + + const std::vector& ImageMetaMaker::Meta() const + { + if(_meta_maker) return _meta_maker->Meta(); + auto sptr = SharedMetaMaker(); + if(sptr) return sptr->Meta(); + + std::cerr << "MetaMaker does not exist!" << std::endl; + throw std::exception(); + } + + const std::vector& ImageMetaMaker::RowCompressionFactor() const + { + if(_meta_maker) return _meta_maker->RowCompressionFactor(); + auto sptr = SharedMetaMaker(); + if(sptr) return sptr->RowCompressionFactor(); + + std::cerr << "MetaMaker does not exist!" << std::endl; + throw std::exception(); + } + + const std::vector& ImageMetaMaker::ColCompressionFactor() const + { + if(_meta_maker) return _meta_maker->ColCompressionFactor(); + auto sptr = SharedMetaMaker(); + if(sptr) return sptr->ColCompressionFactor(); + + std::cerr << "MetaMaker does not exist!" << std::endl; + throw std::exception(); + } + +} +#endif diff --git a/ImageMetaMaker.h b/ImageMetaMaker.h new file mode 100644 index 0000000..ee875ba --- /dev/null +++ b/ImageMetaMaker.h @@ -0,0 +1,66 @@ +/** + * \file ImageMetaMaker.h + * + * \ingroup MeatSlicer + * + * \brief Class def header for a class ImageMetaMaker + * + * @author kazuhiro + */ + +/** \addtogroup MeatSlicer + + @{*/ +#ifndef __IMAGEMETAMAKER_H__ +#define __IMAGEMETAMAKER_H__ + +#include "ImageMetaMakerBase.h" + +namespace larcv { + class SuperaMetaMaker; +} + +namespace supera { + + /** + \class ImageMetaMaker + User defined class ImageMetaMaker ... these comments are used to generate + doxygen documentation! + */ + class ImageMetaMaker{ + + friend class larcv::SuperaMetaMaker; + + public: + + /// Default constructor + ImageMetaMaker() : _meta_maker(nullptr) + {} + + /// Default destructor + virtual ~ImageMetaMaker(){ delete _meta_maker; } + + virtual void configure(const supera::Config_t&); + + const std::vector& Meta() const; + + const std::vector& RowCompressionFactor() const; + + const std::vector& ColCompressionFactor() const; + + inline ImageMetaMakerBase* MetaMakerPtr() + { return _meta_maker; } + + private: + + ImageMetaMakerBase* _meta_maker; + + static ImageMetaMakerBase* _shared_meta_maker; + inline static ImageMetaMakerBase* SharedMetaMaker() { return _shared_meta_maker; } + inline static void SetSharedMetaMaker(ImageMetaMakerBase* ptr) { _shared_meta_maker = ptr; } + + }; +} +#endif +/** @} */ // end of doxygen group + diff --git a/ImageMetaMakerBase.cxx b/ImageMetaMakerBase.cxx new file mode 100644 index 0000000..f5bfe4e --- /dev/null +++ b/ImageMetaMakerBase.cxx @@ -0,0 +1,19 @@ +#ifndef __IMAGEMETAMAKERBASE_CXX__ +#define __IMAGEMETAMAKERBASE_CXX__ + +#include "ImageMetaMakerBase.h" + +namespace supera { + + void ImageMetaMakerBase::configure(const Config_t& cfg) + { + _comp_rows = cfg.get >("EventCompRows"); + _comp_cols = cfg.get >("EventCompCols"); + + if(_comp_rows.size() != _comp_cols.size()) { + std::cerr << "EventCompRows size != EventCompCols size" << std::endl; + throw std::exception(); + } + } +} +#endif diff --git a/ImageMetaMakerBase.h b/ImageMetaMakerBase.h new file mode 100644 index 0000000..806d995 --- /dev/null +++ b/ImageMetaMakerBase.h @@ -0,0 +1,56 @@ +/** + * \file ImageMetaMakerBase.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class ImageMetaMakerBase + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __IMAGEMETAMAKERBASE_H__ +#define __IMAGEMETAMAKERBASE_H__ + +#include "larcv/core/Base/larcv_base.h" +#include "larcv/core/DataFormat/ImageMeta.h" +#include "FMWKInterface.h" + +namespace supera { + + /** + \class ImageMetaMakerBase + User defined class ImageMetaMakerBase ... these comments are used to generate + doxygen documentation! + */ + class ImageMetaMakerBase : public larcv::larcv_base { + + public: + + /// Default constructor + ImageMetaMakerBase(std::string name="NoName") + : larcv_base(name) + {} + + /// Default destructor + virtual ~ImageMetaMakerBase(){} + + virtual void configure(const supera::Config_t&); + + virtual const std::vector& Meta() const = 0; + const std::vector& RowCompressionFactor() const { return _comp_rows; } + const std::vector& ColCompressionFactor() const { return _comp_cols; } + + private: + + std::vector _comp_rows; + std::vector _comp_cols; + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/ImageMetaMakerFactory.cxx b/ImageMetaMakerFactory.cxx new file mode 100644 index 0000000..b947df6 --- /dev/null +++ b/ImageMetaMakerFactory.cxx @@ -0,0 +1,39 @@ +#ifndef __IMAGEMETAMAKERFACTORY_CXX__ +#define __IMAGEMETAMAKERFACTORY_CXX__ + +#include "larcv/core/Base/larcv_logger.h" +#include "ImageMetaMakerFactory.h" +#include "ImageMetaFromConfig.h" +#include "PulledPork3DSlicer.h" + +namespace supera { + + ImageMetaMakerBase* CreateImageMetaMaker(const supera::Config_t& cfg) + { + ImageMetaMakerBase* maker = nullptr; + try{ + LARCV_SINFO() << "Attempting to construct supera::ImageMetaFromConfig... " << std::endl; + auto const& meta_cfg = cfg.get("MetaConfig"); + maker = new ImageMetaFromConfig(); + maker->configure(meta_cfg); + LARCV_SINFO() << "Successfully made supera::ImageMetaFromConfig! " << std::endl; + }catch(...){ + if(maker) delete maker; + } + if(!maker) { + try{ + LARCV_SINFO() << "Attempting to construct supera::PuledPork3DSlicer..." << std::endl; + auto const& meta_cfg = cfg.get("PulledPork"); + maker = new PulledPork3DSlicer(); + maker->configure(meta_cfg); + LARCV_SINFO() << "Successfully made supera::PulledPork3DSlicer! " << std::endl; + }catch(...){ + if(maker) delete maker; + } + } + LARCV_SINFO() << "Returning supera::ImageMetaMakerBase: " << maker << std::endl; + return maker; + } + +} +#endif diff --git a/ImageMetaMakerFactory.h b/ImageMetaMakerFactory.h new file mode 100644 index 0000000..814351e --- /dev/null +++ b/ImageMetaMakerFactory.h @@ -0,0 +1,11 @@ +#ifndef __IMAGEMETAMAKERFACTORY_H__ +#define __IMAGEMETAMAKERFACTORY_H__ + +#include "ImageMetaMakerBase.h" + +namespace supera { + + ImageMetaMakerBase* CreateImageMetaMaker(const supera::Config_t& cfg); + +} +#endif diff --git a/LAr2Image.cxx b/LAr2Image.cxx new file mode 100644 index 0000000..bcda39b --- /dev/null +++ b/LAr2Image.cxx @@ -0,0 +1,424 @@ +#ifndef __SUPERA_LAR2IMAGE_CXX__ +#define __SUPERA_LAR2IMAGE_CXX__ + +#include "LAr2Image.h" +#include "larcv/core/Base/larcv_logger.h" + +namespace supera { + + larcv::Image2D Hit2Image2D(const larcv::ImageMeta & meta, + const std::vector& hits, const int time_offset) + { + //int nticks = meta.rows(); + //int nwires = meta.cols(); + //size_t row_comp_factor = (size_t)(meta.pixel_height()); + const int ymax = meta.max_y() - 1; // Need in terms of row coordinate + const int ymin = (meta.min_y() >= 0 ? meta.min_y() : 0); + larcv::Image2D img(meta); + + LARCV_SINFO() << "Filling an image: " << meta.dump(); + LARCV_SINFO() << "(ymin,ymax) = (" << ymin << "," << ymax << ")" << std::endl; + + for(auto const& h : hits) { + auto const& wire_id = ::supera::ChannelToWireID(h.Channel()); + + if ((int)(wire_id.Plane) != meta.id()) continue; + + size_t col = 0; + try { col = meta.col(wire_id.Wire); } + catch (const larcv::larbys&) { continue; } + + int row = int(h.PeakTime()+0.5) + time_offset; + if(row > ymax || row < ymin) continue; + img.set_pixel(ymax-row,col,h.Integral()); + } + return img; + } + + std::vector Hit2Image2D(const std::vector& meta_v, + const std::vector& hits, + const int time_offset) + { + std::vector res_v; + for (size_t p = 0; p < ::supera::Nplanes(); ++p) { + auto const& meta = meta_v.at(p); + res_v.emplace_back(std::move(Hit2Image2D(meta,hits,time_offset))); + res_v.back().index(res_v.size()-1); + } + return res_v; + } + + larcv::Image2D Wire2Image2D(const larcv::ImageMeta& meta, + const std::vector& wires, + const int time_offset) + { + //int nticks = meta.rows(); + //int nwires = meta.cols(); + size_t row_comp_factor = (size_t)(meta.pixel_height()); + const int ymax = meta.max_y() - 1; // Need in terms of row coordinate + const int ymin = (meta.min_y() >= 0 ? meta.min_y() : 0); + larcv::Image2D img(meta); + img.paint(0.); + + LARCV_SINFO() << "Filling an image: " << meta.dump(); + LARCV_SINFO() << "(ymin,ymax) = (" << ymin << "," << ymax << ")" << std::endl; + + for (auto const& wire : wires) { + + auto const& wire_id = ::supera::ChannelToWireID(wire.Channel()); + + if ((int)(wire_id.Plane) != meta.id()) continue; + + size_t col = 0; + try { + col = meta.col(wire_id.Wire); + } catch (const ::larcv::larbys&) { + continue; + } + + for (auto const& range : wire.SignalROI().get_ranges()) { + + auto const& adcs = range.data(); + //double sumq = 0; + //for(auto const& v : adcs) sumq += v; + //sumq /= (double)(adcs.size()); + //if(sumq<3) continue; + + int start_index = range.begin_index() + time_offset; + int end_index = start_index + adcs.size() - 1; + if (start_index > ymax || end_index < ymin) continue; + + if (row_comp_factor > 1) { + + for (size_t index = 0; index < adcs.size(); ++index) { + if ((int)index + start_index < ymin) continue; + if ((int)index + start_index > ymax) break; + auto row = meta.row((double)(start_index + index)); + img.set_pixel(row, col, adcs[index]); + } + } else { + // Fill matrix from start_index => end_index of matrix row + // By default use index 0=>length-1 index of source vector + int nskip = 0; + int nsample = adcs.size(); + if (end_index > ymax) { + LARCV_SDEBUG() << "End index (" << end_index << ") exceeding image bound (" << ymax << ")" << std::endl; + nsample = adcs.size() - (end_index - ymax); + end_index = ymax; + LARCV_SDEBUG() << "Corrected End index = " << end_index << std::endl; + } + if (start_index < ymin) { + LARCV_SDEBUG() << "Start index (" << start_index << ") exceeding image bound (" << ymin << ")" << std::endl; + nskip = ymin - start_index; + nsample -= nskip; + start_index = ymin; + LARCV_SDEBUG() << "Corrected Start index = " << start_index << std::endl; + } + LARCV_SDEBUG() << "Calling a reverse_copy..." << std::endl + << " source wf : start index = " << range.begin_index() << " length = " << adcs.size() << std::endl + << " (row,col) : (" << (ymax - end_index) << "," << col << ")" << std::endl + << " nskip : " << nskip << std::endl + << " nsample : " << nsample << std::endl; + try { + img.reverse_copy(ymax - end_index, + col, + adcs, + nskip, + nsample); + } catch (const ::larcv::larbys& err) { + LARCV_SCRITICAL() << "Attempted to fill an image..." << std::endl + << meta.dump() + << "(ymin,ymax) = (" << ymin << "," << ymax << ")" << std::endl + << "Called a reverse_copy..." << std::endl + << " source wf : plane = " << wire_id.Plane << " wire = " << wire_id.Wire << std::endl + << " timing : start index = " << range.begin_index() << " length = " << adcs.size() << std::endl + << " (row,col) : (" << (ymax - end_index) << "," << col << ")" << std::endl + << " nskip : " << nskip << std::endl + << "Re-throwing an error:" << std::endl; + throw err; + } + } + } + } + return img; + } + + std::vector + Wire2Image2D(const std::vector& meta_v, + const std::vector& wires, + const int time_offset) + { + std::vector res_v; + for (size_t p = 0; p < ::supera::Nplanes(); ++p) { + auto const& meta = meta_v.at(p); + res_v.emplace_back(std::move(Wire2Image2D(meta,wires,time_offset))); + res_v.back().index(res_v.size()-1); + } + return res_v; + } + + larcv::Image2D OpDigit2Image2D(const larcv::ImageMeta& meta, + const std::vector& opdigit_v, + int time_offset) + { + larcv::Image2D img(meta); + img.paint(2048); + + std::vector tmp_wf(meta.rows(), 2048); + for (auto const& opdigit : opdigit_v) { + if (opdigit.size() < 1000) continue; + auto const col = opdigit.ChannelNumber(); + if (meta.min_x() > col) continue; + if (col >= meta.max_x()) continue; + // + // HACK: right way is to use TimeService + trigger. + // for now I just record PMT beamgate tick=0 as edge of an image (w/ offset) + // + size_t nskip = 0; + if (time_offset < 0) nskip = (-1 * time_offset); + if (nskip >= opdigit.size()) continue; + for (auto& v : tmp_wf) v = 2048; + size_t num_pixel = std::min(meta.rows(), opdigit.size() - nskip); + for (size_t i = 0; i < num_pixel; ++i) tmp_wf[i] = (float)(opdigit[nskip + i]); + img.copy(0, col, &(tmp_wf[0]), num_pixel); + //img.reverse_copy(0,col,opdigit,nskip,num_pixel); + } + return img; + } + /* + std::vector + SimCh2Image2D(const std::vector& meta_v, + const std::vector& track2type_v, + const std::vector& sch_v, + const int time_offset) + { + LARCV_SINFO() << "Filling semantic-segmentation ground truth image..." << std::endl; + std::vector img_v; + for (auto const& meta : meta_v) { + LARCV_SINFO() << meta.dump(); + img_v.emplace_back(larcv::Image2D(meta)); + } + + static std::vector column; + for (auto const& img : img_v) { + if (img.meta().rows() >= column.size()) + column.resize(img.meta().rows() + 1, (float)(::larcv::kROIUnknown)); + } + + for (auto const& sch : sch_v) { + auto ch = sch.Channel(); + auto const& wid = ::supera::ChannelToWireID(ch); + auto const& plane = wid.Plane; + auto& img = img_v.at(plane); + auto const& meta = img.meta(); + + size_t col = wid.Wire; + if (col < meta.min_x()) continue; + if (meta.max_x() <= col) continue; + if (plane != img.meta().id()) continue; + + col -= (size_t)(meta.min_x()); + + // Initialize column vector + for (auto& v : column) v = (float)(::larcv::kROIUnknown); + //for (auto& v : column) v = (float)(-1); + + for (auto const tick_ides : sch.TDCIDEMap()) { + int tick = supera::TPCTDC2Tick((double)(tick_ides.first)) + time_offset; + if (tick < meta.min_y()) continue; + if (tick >= meta.max_y()) continue; + // Where is this tick in column vector? + size_t index = (size_t)(meta.max_y() - tick); + // Pick type + double energy = 0; + ::larcv::ROIType_t roi_type =::larcv::kROIUnknown; + for (auto const& edep : tick_ides.second) { + if (edep.energy < energy) continue; + if (std::abs(edep.trackID) >= (int)(track2type_v.size())) continue; + auto temp_roi_type = track2type_v[std::abs(edep.trackID)]; + if (temp_roi_type ==::larcv::kROIUnknown) continue; + energy = edep.energy; + roi_type = (::larcv::ROIType_t)temp_roi_type; + } + column[index] = roi_type; + } + // mem-copy column vector + img.copy(0, col, column, img.meta().rows()); + } + return img_v; + } + */ + /* + larcv::Voxel3DSet + SimCh2Voxel3D(const larcv::Voxel3DMeta& meta, + const std::vector& track_v, + const std::vector& sch_v, + const int time_offset, + const size_t plane) + { + LARCV_SINFO() << "Filling Voxel3D ground truth volume..." << std::endl; + larcv::Voxel3DSet res(meta); + //double x, y, z, x_tick; + double y, z, x_tick; + //std::cout << "x_offset " << x_offset << std::endl; + for (auto const& sch : sch_v) { + auto ch = sch.Channel(); + + auto const& wid = ::supera::ChannelToWireID(ch); + if( plane != (size_t)(wid.Plane) ) continue; + + for (auto const tick_ides : sch.TDCIDEMap()) { + + x_tick = (supera::TPCTDC2Tick(tick_ides.first) + time_offset) * supera::TPCTickPeriod() * supera::DriftVelocity(); + + //std::cout << tick_ides.first << " : " << supera::TPCTDC2Tick(tick_ides.first) << " : " << time_offset << " : " << x_tick << std::flush; + //std::cout << (supera::TPCTDC2Tick(tick_ides.first) + time_offset) << std::endl + //<< (supera::TPCTDC2Tick(tick_ides.first) + time_offset) * supera::TPCTickPeriod() << std::endl + //<< (supera::TPCTDC2Tick(tick_ides.first) + time_offset) * supera::TPCTickPeriod() * supera::DriftVelocity() << std::endl + //<< std::endl; + + for (auto const& edep : tick_ides.second) { + + if (std::abs(edep.trackID) >= (int)(track_v.size())) continue; + + if (track_v[std::abs(edep.trackID)]<=0) continue; + + //x = edep.x; + y = edep.y; + z = edep.z; + //supera::ApplySCE(x,y,z); + //std::cout << " ... " << x << std::endl; + // Now use tick-based position for x + auto vid = meta.ID(x_tick,y,z); + if(vid == larcv::kINVALID_VOXEL3DID) continue; + + larcv::Voxel3D vx(vid,edep.energy); + res.Emplace(std::move(vx)); + } + } + } + return res; + } + */ + /* + std::vector > + SimCh2Pixel2DCluster(const std::vector& meta_v, + const std::vector& row_compression_v, + const std::vector& col_compression_v, + const std::vector& sch_v, + const std::vector& trackid2cluster, + const int time_offset) + { + std::vector > res_vv; + + static std::vector column; + for (auto const& meta : meta_v) { + if (meta.rows() >= column.size()) + column.resize(meta.rows() + 1, 0); + } + + // figure out # of clusters + if(meta_v.size() != supera::Nplanes()) { + LARCV_SCRITICAL() << "# Meta mismatch with # planes!" << std::endl; + throw larcv::larbys(); + } + // figure out # of clusters to be made + size_t num_clusters=0; + for(auto const& cidx : trackid2cluster) { + if(cidx == larcv::kINVALID_SIZE) continue; + if(cidx >= num_clusters) num_clusters = cidx + 1; + } + // loop over cluster index, construct cluster + std::vector img_v; + for(size_t plane=0; plane nonzero_npx_v(supera::Nplanes(),0); + + for(size_t cidx=0; cidx= meta.max_y()) continue; + // Where is this tick in column vector? + size_t index = (size_t)(meta.max_y() - tick); + // Accummulate energy for relevant cluster + int trackid = 0; + double energy = 0; + for (auto const& edep : tick_ides.second) { + trackid = std::abs(edep.trackID); + if (trackid >= (int)(trackid2cluster.size())) continue; + if (trackid2cluster[trackid] != cidx) continue; + energy += edep.energy; + } + if(energy>0) { + column[index] = energy; + ++nonzero_npx; + } + } + // mem-copy column vector + img.copy(0, col, column, img.meta().rows()); + } + + // Now convert them into Pixel2DCluster + std::vector res_v; + res_v.reserve(supera::Nplanes()); + larcv::Pixel2D px; + for(size_t plane=0; plane Image2D + // + larcv::Image2D Hit2Image2D(const larcv::ImageMeta& meta, + const std::vector& hits, + const int time_offset=0); + + std::vector Hit2Image2D(const std::vector& meta_v, + const std::vector& hits, + const int time_offset=0); + + // + // Wire => Image2D + // + larcv::Image2D Wire2Image2D(const larcv::ImageMeta& meta, + const std::vector& wires, + const int time_offset=0); + + std::vector Wire2Image2D(const std::vector& meta_v, + const std::vector& wires, + const int time_offset=0); + + // + // OpDigit => Image2D + // + larcv::Image2D OpDigit2Image2D(const larcv::ImageMeta& meta, + const std::vector& opdigit_v, + int time_offset=0); + + // + // SimChannel => Image2D + // + /* + std::vector SimCh2Image2D(const std::vector& meta_v, + const std::vector& track2type_v, + const std::vector& sch_v, + const int time_offset); + */ + // + // SimChannel => Voxel3D + // + /* + larcv::Voxel3DSet + SimCh2Voxel3D(const larcv::Voxel3DMeta& meta, + const std::vector& track_v, + const std::vector& sch_v, + const int time_offset, + const size_t plane); + */ + // + // SimChannel => Pixel2DCluster + // + /* + std::vector > + SimCh2Pixel2DCluster(const std::vector& meta_v, + const std::vector& row_compression_v, + const std::vector& col_compression_v, + const std::vector& sch_v, + const std::vector& trackid2cluster, + const int time_offset); + */ +} +#endif +//#endif +//#endif diff --git a/LArCVMetaData.h b/LArCVMetaData.h new file mode 100644 index 0000000..b494eab --- /dev/null +++ b/LArCVMetaData.h @@ -0,0 +1,80 @@ + +#ifndef __LARCVMETADATA_H__ +#define __LARCVMETADATA_H__ + +#include +#include +#include + +namespace larcv { + + namespace sam { + + struct FCLMetaData_t { + std::string name; + std::string version; + std::string data_tier; + std::string data_stream; + FCLMetaData_t() : name (" ") + , version (" ") + , data_tier (" ") + , data_stream (" ") + {} + }; + + struct UBMetaData_t { + std::string project_name; + std::string project_stage; + std::string project_version; + UBMetaData_t() : project_name (" ") + , project_stage (" ") + , project_version (" ") + {} + }; + + struct FileCatalogMetaData_t { + std::string file_format; + std::string file_type; + std::string group; + std::string application_family; + std::string application_name; + std::string application_version; + FileCatalogMetaData_t() : file_format ("larcv") + , file_type (" ") + , group ("uboone") + , application_family ("art") + , application_name (" ") + , application_version (" ") + + {} + }; + + struct RunMetaData_t { + std::string run_type; + std::set subruns; + RunMetaData_t() : run_type(" ") + , subruns() + {} + }; + + struct SAMBuiltInMetaData_t { + size_t first_event; + size_t last_event; + size_t event_count; + std::string start_time; + std::string end_time; + std::set parents; + std::map runs_m; + SAMBuiltInMetaData_t() : first_event (0) + , last_event (0) + , event_count (0) + , start_time (" ") + , end_time (" ") + , parents () + , runs_m () + {} + }; + + } +} +#endif diff --git a/LArCVMetaMaker.h b/LArCVMetaMaker.h new file mode 100644 index 0000000..0407d44 --- /dev/null +++ b/LArCVMetaMaker.h @@ -0,0 +1,68 @@ +//////////////////////////////////////////////////////////////////////// +// +// LArCVMetaMaker.h +// +//////////////////////////////////////////////////////////////////////// +#ifndef LARCVMETAMAKER_H +#define LARCVMETAMAKER_H + +#include "fhiclcpp/ParameterSet.h" +#include "fhiclcpp/make_ParameterSet.h" +#include "art/Framework/Services/Registry/ActivityRegistry.h" +#include "art/Framework/Services/Registry/ServiceHandle.h" +#include "art/Framework/Services/Registry/ServiceMacros.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "canvas/Persistency/Common/Ptr.h" +#include "canvas/Persistency/Common/PtrVector.h" + +#include "LArCVMetaData.h" + +namespace util{ + + class LArCVMetaMaker { + + public: + LArCVMetaMaker(fhicl::ParameterSet const& pset, art::ActivityRegistry& reg); + + ~LArCVMetaMaker(){}; + + public: + + /// Re-configure the service module + void reconfigure(fhicl::ParameterSet const& pset); + + /// Function to be executed @ run boundary + void preBeginRun(art::Run const& run); + void postBeginRun(art::Run const& run); + /// Function to be executed @ event boundary + void preProcessEvent(const art::Event& evt); + void postProcessEvent(const art::Event& evt); + /// Function to be executed @ file open + void preOpenFile(const std::string& filename); + void postOpenFile(const std::string& filename); + + void postBeginJob(); + void postEndJob(); + + std::string GetContent(std::string stream_name) const; + + void addJson(const std::string fname, const std::string strm) { _json_v.push_back(fname + ".json"); _stream_v.push_back(strm); } + + protected: + bool _quiet; + std::vector _json_v; + std::vector _stream_v; + ::larcv::sam::FCLMetaData_t _fcl_meta; + ::larcv::sam::UBMetaData_t _ub_meta; + ::larcv::sam::FileCatalogMetaData_t _fcat_meta; + ::larcv::sam::SAMBuiltInMetaData_t _sam_meta; + + }; // class LArCVMetaMaker + +} //namespace utils + +DECLARE_ART_SERVICE(util::LArCVMetaMaker, LEGACY) + +#endif diff --git a/LArCVMetaMaker_service.cc b/LArCVMetaMaker_service.cc new file mode 100644 index 0000000..c1557ae --- /dev/null +++ b/LArCVMetaMaker_service.cc @@ -0,0 +1,225 @@ + +#include "uboone/Utilities/FileCatalogMetadataMicroBooNE.h" +#include "art/Framework/Services/Registry/ServiceHandle.h" +#include "art/Framework/Services/System/FileCatalogMetadata.h" + +#include "LArCVMetaMaker.h" +#include +#include +#include + +//----------------------------------------------------------------------------------------- +util::LArCVMetaMaker::LArCVMetaMaker(fhicl::ParameterSet const& pset, art::ActivityRegistry ®) + : _quiet(true) +//---------------------------------------------------------------------------------------- +{ + _json_v.clear(); + reconfigure(pset); + + if(!_quiet) { + reg.sPostOpenFile.watch (this, &LArCVMetaMaker::postOpenFile ); + + reg.sPreBeginRun.watch (this, &LArCVMetaMaker::preBeginRun ); + reg.sPostBeginRun.watch (this, &LArCVMetaMaker::postBeginRun ); + + reg.sPreProcessEvent.watch (this, &LArCVMetaMaker::preProcessEvent ); + reg.sPostProcessEvent.watch (this, &LArCVMetaMaker::postProcessEvent ); + + reg.sPostBeginJob.watch (this, &LArCVMetaMaker::postBeginJob ); + reg.sPostEndJob.watch (this, &LArCVMetaMaker::postEndJob ); + } + + _fcl_meta.data_tier = "larcv"; + _fcat_meta.file_format = "larcv"; + +} + +//------------------------------------------------------------------ +void util::LArCVMetaMaker::reconfigure(fhicl::ParameterSet const& pset) +//------------------------------------------------------------------ +{ + _quiet = !(pset.get("Enable",false)); +} + +//------------------------------------------------------------------ +void util::LArCVMetaMaker::postBeginJob() +//------------------------------------------------------------------ +{ + _sam_meta.start_time = TTimeStamp().AsString("s"); // UTC time stamp in SQL format + art::ServiceHandle larmeta_handle; + + art::FileCatalogMetadata::collection_type larmeta; + larmeta_handle->getMetadata(larmeta); + + for(auto const& key_value : larmeta) { + if (key_value.first == "file_type" ) _fcat_meta.file_type = key_value.second; + else if (key_value.first == "group" ) _fcat_meta.group = key_value.second; + else if (key_value.first == "applicationFamily" ) _fcat_meta.application_family = key_value.second; + else if (key_value.first == "process_name" ) _fcat_meta.application_name = key_value.second; + else if (key_value.first == "applicationVersion") _fcat_meta.application_version = key_value.second; + } + +} + +//------------------------------------------------------------------ +void util::LArCVMetaMaker::postEndJob() +//------------------------------------------------------------------ +{ + _sam_meta.end_time = TTimeStamp().AsString("s"); // UTC time stamp in SQL format + + art::ServiceHandle ubmeta_handle; + + _fcl_meta.name = ubmeta_handle->FCLName(); + _fcl_meta.version = ubmeta_handle->FCLVersion(); + + _ub_meta.project_name = ubmeta_handle->ProjectName(); + _ub_meta.project_stage = ubmeta_handle->ProjectStage(); + _ub_meta.project_version = ubmeta_handle->ProjectVersion(); + + + // + // Create json + // + for(size_t json_index=0; json_index < _json_v.size(); ++json_index) { + + auto const& json_name = _json_v[json_index]; + auto const& strm_name = _stream_v[json_index]; + + std::string content = this->GetContent(strm_name); + + std::ofstream fout(json_name); + fout << content.c_str() << std::endl; + fout.close(); + } + +} + +//------------------------------------------------------------ +void util::LArCVMetaMaker::preProcessEvent(const art::Event& evt) +//------------------------------------------------------------ +{ + std::cout << "This is before event process" << std::endl; +} + +//------------------------------------------------------------ +void util::LArCVMetaMaker::postProcessEvent(const art::Event& evt) +//------------------------------------------------------------ +{ + size_t run = evt.run(); + size_t subrun = evt.subRun(); + size_t event = evt.event(); + + auto iter = _sam_meta.runs_m.find(run); + if(iter == _sam_meta.runs_m.end()) { + // New run found. Insert RunMetaData_t + iter = (_sam_meta.runs_m.emplace(run,::larcv::sam::RunMetaData_t())).first; + (*iter).second.run_type = "\" \""; + + art::ServiceHandle larmeta_handle; + art::FileCatalogMetadata::collection_type larmeta; + larmeta_handle->getMetadata(larmeta); + for(auto const& key_value : larmeta) { + if(key_value.first != "run_type") continue; + (*iter).second.run_type = key_value.second; + break; + } + } + + auto& run_meta = (*iter).second; + run_meta.subruns.insert(subrun); + + if(_sam_meta.event_count == 0) _sam_meta.first_event = event; + _sam_meta.last_event = event; + ++_sam_meta.event_count; +} + +//------------------------------------------------------ +void util::LArCVMetaMaker::preBeginRun(art::Run const& run) +//------------------------------------------------------ +{} + +//------------------------------------------------------ +void util::LArCVMetaMaker::postBeginRun(art::Run const& run) +//------------------------------------------------------ +{} + +//--------------------------------------------------------------- +void util::LArCVMetaMaker::postOpenFile(const std::string& filename) +//--------------------------------------------------------------- +{ + _sam_meta.parents.insert(filename); +} + +//---------------------------------------------------------------------- +std::string util::LArCVMetaMaker::GetContent(std::string stream_name) const +//---------------------------------------------------------------------- +{ + std::stringstream msg; + msg << "{\n" + + << " \"application\": {\n" + << " \"family\" : " << _fcat_meta.application_family << ",\n" + << " \"name\" : " << _fcat_meta.application_name << ",\n" + << " \"version\" : " << _fcat_meta.application_version << "\n" + << " },\n" + << " \"file_format\" : \"" << _fcat_meta.file_format << "\",\n" + << " \"file_type\" : " << _fcat_meta.file_type << ",\n" + << " \"group\" : " << _fcat_meta.group << ",\n" + + << " \"fcl.name\" : \"" << _fcl_meta.name << "\",\n" + << " \"fcl.version\" : \"" << _fcl_meta.version << "\",\n" + << " \"data_tier\" : \"" << _fcl_meta.data_tier << "\",\n" + << " \"data_stream\" : \"" << stream_name << "\",\n" + + << " \"ub_project.name\" : \"" << _ub_meta.project_name << "\",\n" + << " \"ub_project.stage\" : \"" << _ub_meta.project_stage << "\",\n" + << " \"ub_project.version\" : \"" << _ub_meta.project_version << "\",\n" + + << " \"start_time\" : \"" << _sam_meta.start_time << "\",\n" + << " \"end_time\" : \"" << _sam_meta.end_time << "\",\n" + << " \"first_event\" : " << _sam_meta.first_event << ",\n" + << " \"last_event\" : " << _sam_meta.last_event << ",\n" + << " \"event_count\" : " << _sam_meta.event_count << ",\n" + << " \"parents\" : [\n"; + + size_t ctr=0; + for(auto const& parent : _sam_meta.parents) { + size_t name_start = parent.rfind("/"); + if(name_start > parent.length()) name_start = 0; + else ++name_start; + msg << " { \"file_name\" : \"" << parent.substr(name_start) << "\" }"; + ++ctr; + if(ctr==_sam_meta.parents.size()) msg << "\n"; + else msg << ",\n"; + } + + msg << " ],\n" + << " \"runs\" : [\n"; + + ctr=0; + for(auto const& run_meta : _sam_meta.runs_m) { + ++ctr; + size_t subrun_ctr=0; + auto const& run = run_meta.first; + auto const& run_type = run_meta.second.run_type; + for(auto const& subrun : run_meta.second.subruns) { + + msg << " [ " << run << ", " << subrun << ", " << run_type << "]"; + ++subrun_ctr; + if(ctr == _sam_meta.runs_m.size() && subrun_ctr == run_meta.second.subruns.size()) + msg << "\n"; + else + msg << ",\n"; + } + } + msg << " ]\n" + << "}\n"; + return msg.str(); +} + +namespace util{ + + DEFINE_ART_SERVICE(LArCVMetaMaker) + +} // namespace util + diff --git a/LArCVSuperaDriver.cxx b/LArCVSuperaDriver.cxx new file mode 100644 index 0000000..0534758 --- /dev/null +++ b/LArCVSuperaDriver.cxx @@ -0,0 +1,98 @@ +#ifndef LARCVSUPERADRIVER_CXX +#define LARCVSUPERADRIVER_CXX + +#include "LArCVSuperaDriver.h" + +namespace larcv { + + LArCVSuperaDriver::LArCVSuperaDriver() + : _driver("ProcessDriver") + , _supera_chstatus_ptr(nullptr) + {} + + void LArCVSuperaDriver::SetCSV(std::string proc_name, std::string fname) + { + auto const pid = _driver.process_id(proc_name); + if(pid >= _driver.process_names().size()) { + LARCV_CRITICAL() << "Invalid process name (" << proc_name << ") to set CSV file for..." << std::endl; + throw larbys(); + } + ((SuperaBase*)(_driver.process_ptr(pid)))->SetCSV(fname); + } + + void LArCVSuperaDriver::configure(const std::string cfg_file) + { + _driver.configure(cfg_file); + } + + void LArCVSuperaDriver::configure(const larcv::PSet& cfg) + { + _driver.configure(cfg); + } + + void LArCVSuperaDriver::override_input_file(const std::vector& flist) + { + _driver.override_input_file(flist); + } + + void LArCVSuperaDriver::override_output_file(const std::string fname) + { + _driver.override_output_file(fname); + } + + SuperaChStatus* LArCVSuperaDriver::SuperaChStatusPointer() + { return _supera_chstatus_ptr; } + + const std::set& LArCVSuperaDriver::DataLabels(supera::LArDataType_t type) const + { + static std::set empty_string; + auto iter = _data_request_m.find(type); + if(iter == _data_request_m.end()) return empty_string; + return (*iter).second; + } + + void LArCVSuperaDriver::initialize() { + + _driver.initialize(); + _supera_idx_v.clear(); + + for(size_t idx=0; idx<_driver.process_names().size(); ++idx) { + + auto proc_ptr = _driver.process_ptr(idx); + + if(proc_ptr->is("SuperaMetaMaker") && idx) { + LARCV_CRITICAL() << "SuperaMetaMaker must be the first module!" << std::endl; + throw larbys(); + } + + if(proc_ptr->is("Supera") || proc_ptr->is("SuperaMetaMaker")) { + _supera_idx_v.push_back(idx); + for(size_t data_type=0; data_type<(size_t)(supera::LArDataType_t::kLArDataTypeMax); ++data_type) { + auto const& label = ((SuperaBase*)proc_ptr)->LArDataLabel((supera::LArDataType_t)data_type); + if(label.empty()) continue; + _data_request_m[(supera::LArDataType_t)(data_type)].insert(label); + } + } + + if(_driver.process_ptr(idx)->is("SuperaChStatus")) { + _supera_chstatus_ptr = (SuperaChStatus*)(_driver.process_ptr(idx)); + for(size_t data_type=0; data_type<(size_t)(supera::LArDataType_t::kLArDataTypeMax); ++data_type) { + auto const& label = _supera_chstatus_ptr->LArDataLabel((supera::LArDataType_t)data_type); + if(label.empty()) continue; + _data_request_m[(supera::LArDataType_t)(data_type)].insert(label); + } + } + + } + } + + bool LArCVSuperaDriver::process(size_t run, size_t subrun, size_t event) + { + _driver.set_id(run,subrun,event); + return _driver.process_entry(); + } + + void LArCVSuperaDriver::finalize() { _driver.finalize(); } + +} +#endif diff --git a/LArCVSuperaDriver.h b/LArCVSuperaDriver.h new file mode 100644 index 0000000..4c6612a --- /dev/null +++ b/LArCVSuperaDriver.h @@ -0,0 +1,90 @@ +/** + * \file LArCVSuperaDriver.h + * + * \ingroup MeatSlicer + * + * \brief Class def header for a class LArCVSuperaDriver + * + * @author kazuhiro + */ + +/** \addtogroup MeatSlicer + + @{*/ +#ifndef LARCVSUPERADRIVER_H +#define LARCVSUPERADRIVER_H +//#ifndef __CINT__ +//#ifndef __CLING__ +#include +#include "larcv/core/Base/larcv_base.h" +#include "larcv/core/Processor/ProcessDriver.h" +#include "FMWKInterface.h" +#include "SuperaTypes.h" +#include "SuperaBase.h" +#include "SuperaChStatus.h" + +namespace larcv { + /** + \class LArCVSuperaDriver + User defined class LArCVSuperaDriver ... these comments are used to generate + doxygen documentation! + */ + class LArCVSuperaDriver : public larcv_base { + + public: + + /// Default constructor + LArCVSuperaDriver(); + + /// Default destructor + ~LArCVSuperaDriver(){} + + void configure(const std::string cfg_file); + + void configure(const larcv::PSet& cfg); + + void override_input_file(const std::vector& flist); + + void override_output_file(const std::string fname); + + const std::set& DataLabels(supera::LArDataType_t type) const; + + template + void SetDataPointer(const std::vector& data, const std::string label) + { + LARCV_INFO() << "Received LArDataType_t " << (int)(supera::LArDataType()) << " by label " << label << std::endl; + for(auto& idx : _supera_idx_v) { + auto supera_ptr = (SuperaBase*)(_driver.process_ptr(idx)); + if(supera_ptr->LArDataLabel(supera::LArDataType()) != label) continue; + LARCV_INFO() << "Data pointer provided to: " << supera_ptr->name() << std::endl; + supera_ptr->LArData(data); + } + } + + SuperaChStatus* SuperaChStatusPointer(); + + void initialize(); + bool process(size_t run, size_t subrun, size_t event); + void finalize(); + + void SetCSV(std::string proc_name, std::string fname); + + inline std::vector ProcessNames() const + { return _driver.process_names(); } + + private: + + ProcessDriver _driver; + std::vector _supera_idx_v; + + std::map > _data_request_m; + SuperaChStatus* _supera_chstatus_ptr; + + }; + +} +#endif +//#endif +//#endif +/** @} */ // end of doxygen group + diff --git a/LArSoftSuperaDriver_module.cc b/LArSoftSuperaDriver_module.cc new file mode 100644 index 0000000..96ed7c0 --- /dev/null +++ b/LArSoftSuperaDriver_module.cc @@ -0,0 +1,284 @@ +//////////////////////////////////////////////////////////////////////// +// Class: LArSoftSuperaDriver +// Module Type: analyzer +// File: LArSoftSuperaDriver_module.cc +// +// Generated at Tue May 2 17:36:15 2017 by Kazuhiro Terao using artmod +// from cetpkgsupport v1_11_00. +//////////////////////////////////////////////////////////////////////// + +#include "art/Framework/Core/EDAnalyzer.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" + +#include "nusimdata/SimulationBase/MCTruth.h" +#include "lardataobj/RecoBase/Hit.h" +#include "lardataobj/RecoBase/Wire.h" +#include "lardataobj/RawData/OpDetWaveform.h" +#include "lardataobj/MCBase/MCShower.h" +#include "lardataobj/MCBase/MCTrack.h" +#include "lardataobj/Simulation/SimChannel.h" +#include "larevt/CalibrationDBI/Interface/ChannelStatusService.h" +#include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h" +#include "larcore/Geometry/Geometry.h" +#include +#include + +#include "LArCVMetaMaker.h" +#include "LArCVSuperaDriver.h" +#include "larcv/core/Base/PSet.h" + +class LArSoftSuperaDriver; + +class LArSoftSuperaDriver : public art::EDAnalyzer { +public: + explicit LArSoftSuperaDriver(fhicl::ParameterSet const & p); + // The destructor generated by the compiler is fine for classes + // without bare pointers or other resource use. + + // Plugins should not be copied or assigned. + LArSoftSuperaDriver(LArSoftSuperaDriver const &) = delete; + LArSoftSuperaDriver(LArSoftSuperaDriver &&) = delete; + LArSoftSuperaDriver & operator = (LArSoftSuperaDriver const &) = delete; + LArSoftSuperaDriver & operator = (LArSoftSuperaDriver &&) = delete; + + // Required functions. + void analyze(art::Event const & e) override; + + void beginJob() override; + void endJob() override; +private: + + // Declare member data here. + larcv::LArCVSuperaDriver _supera; +}; + + +LArSoftSuperaDriver::LArSoftSuperaDriver(fhicl::ParameterSet const & p) + : + EDAnalyzer(p) // , + // More initializers here. +{ + + std::string supera_cfg; + cet::search_path finder("FHICL_FILE_PATH"); + + if( !finder.find_file(p.get("supera_params"), supera_cfg) ) + throw cet::exception("LArSoftSuperaDriver") << "Unable to find supera cfg in " << finder.to_string() << "\n"; + + _supera.configure(supera_cfg); + + auto process_names = _supera.ProcessNames(); + for(auto const& proc_name : process_names) { + std::string param_name = "CSV" + proc_name; + auto constraint_file = p.get(param_name.c_str(),""); + if(constraint_file.empty()) continue; + + std::string fullpath; + if( !finder.find_file(constraint_file,fullpath) ) + throw cet::exception("LArSoftSuperaDriver") << "Unable to find CSV file " << constraint_file << "\n"; + + _supera.SetCSV(proc_name,fullpath); + } + + // Decide on output filename + auto out_fname = p.get("out_filename",""); + if(p.get("unique_filename") || out_fname.empty()) { + TString tmp_fname; + if(out_fname.empty()) + tmp_fname = "emptyname_" + p.get("stream"); + else { + tmp_fname = out_fname; + tmp_fname.ReplaceAll(".root",""); + tmp_fname += "_" + p.get("stream"); + } + TTimeStamp ts; + out_fname = Form("%s_%08d_%06d_%06d.root",tmp_fname.Data(),ts.GetDate(),ts.GetTime(), (int)(ts.GetNanoSec()/1.e3)); + } + + _supera.override_output_file(out_fname); + + art::ServiceHandle metamaker; + metamaker->addJson(out_fname,p.get("stream")); +} + +void LArSoftSuperaDriver::beginJob() +{ + _supera.initialize(); +} + +void LArSoftSuperaDriver::analyze(art::Event const & e) +{ + + // + // set data pointers + // + + // hit + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArHit_t)) { + if(label.empty()) continue; + art::Handle > data_h; + if(label.find(" ") > data_h; + if(label.find(" ") > data_h; + if(label.find(" ") > data_h; + if(label.find(" ") > data_h; + if(label.find(" ") > data_h; + if(label.find(" ") > data_h; + if(label.find(" ")(); + const lariov::ChannelStatusProvider& chanFilt = art::ServiceHandle()->GetProvider(); + for(size_t i=0; i < geom->Nchannels(); ++i) { + auto const wid = geom->ChannelToWire(i).front(); + if (!chanFilt.IsPresent(i)) supera_chstatus->set_chstatus(wid.Plane, wid.Wire, ::larcv::chstatus::kNOTPRESENT); + else supera_chstatus->set_chstatus(wid.Plane, wid.Wire, (short)(chanFilt.Status(i))); + } + + /* + std::vector filled_ch( ::larcv::supera::Nchannels(), false ); + // If specified check RawDigit pedestal value: if negative this channel is not used by wire (set status=>-2) + if(!_core.producer_digit().empty()) { + art::Handle > digit_h; + e.getByLabel(_core.producer_digit(),digit_h); + for(auto const& digit : *digit_h) { + auto const ch = digit.Channel(); + if(ch >= filled_ch.size()) throw ::larcv::larbys("Found RawDigit > possible channel number!"); + if(digit.GetPedestal()<0.) { + _core.set_chstatus(ch,::larcv::chstatus::kNEGATIVEPEDESTAL); + filled_ch[ch] = true; + } + } + } + + // Set database status + const lariov::ChannelStatusProvider& chanFilt = art::ServiceHandle()->GetProvider(); + for(size_t i=0; i < ::larcv::supera::Nchannels(); ++i) { + if ( filled_ch[i] ) continue; + if (!chanFilt.IsPresent(i)) _core.set_chstatus(i,::larcv::chstatus::kNOTPRESENT); + else _core.set_chstatus(i,(short)(chanFilt.Status(i))); + } + */ + } + + // + // execute supera + // + _supera.process(e.id().run(),e.id().subRun(),e.id().event()); +} + +void LArSoftSuperaDriver::endJob() +{ + _supera.finalize(); +} + +DEFINE_ART_MODULE(LArSoftSuperaDriver) diff --git a/LinkDef.h b/LinkDef.h new file mode 100644 index 0000000..886121d --- /dev/null +++ b/LinkDef.h @@ -0,0 +1,53 @@ +// +// cint script to generate libraries +// Declaire namespace & classes you defined +// #pragma statement: order matters! Google it ;) +// + +#ifdef __CINT__ +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ namespace supera; +//#pragma link C++ class larlite::Supera+; +//#pragma link C++ class supera::Cropper+; +#pragma link C++ class std::set+; +//#pragma link C++ class larcv::SuperaWire+; +//#pragma link C++ class larcv::SuperaHit+; +//#pragma link C++ class larcv::SuperaSimCh+; +//#pragma link C++ class larcv::SuperaBase+; +//#pragma link C++ class larcv::SuperaOpDigit+; +//#pragma link C++ class larcv::SuperaChStatus+; +//#pragma link C++ class supera::MCParticleTree+; +//#pragma link C++ class supera::MCROIMaker+; +#pragma link C++ class larcv::LArCVSuperaDriver; +#pragma link C++ class larlite::LArLiteSuperaDriver+; +//#pragma link C++ class larcv::SuperaMCPCluster+; +//#pragma link C++ class larcv::SuperaKeyPointCluster+; +#pragma link C++ class supera::GridPoint3D+; +#pragma link C++ class supera::WireRange3D+; +#pragma link C++ class std::vector+; +//#pragma link C++ class supera::ImageMetaMakerBase+; +//#pragma link C++ class supera::PulledPork3DSlicer+; +//ADD_NEW_CLASS ... do not change this line +#endif + + + + + + + + + + + + + + + + + + + diff --git a/ParamsChStatus.cxx b/ParamsChStatus.cxx new file mode 100644 index 0000000..5a338d3 --- /dev/null +++ b/ParamsChStatus.cxx @@ -0,0 +1,13 @@ +#ifndef __SUPERAPARAMSCHSTATUS_CXX__ +#define __SUPERAPARAMSCHSTATUS_CXX__ + +#include "ParamsChStatus.h" + +namespace supera { + + void ParamsChStatus::configure(const supera::Config_t& cfg) + { + _out_chstatus_producer = cfg.get("OutChStatusLabel", ""); + } +} +#endif diff --git a/ParamsChStatus.h b/ParamsChStatus.h new file mode 100644 index 0000000..3e9b67a --- /dev/null +++ b/ParamsChStatus.h @@ -0,0 +1,53 @@ +/** + * \file ParamsChStatus.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class ParamsChStatus + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAPARAMSCHSTATUS_H__ +#define __SUPERAPARAMSCHSTATUS_H__ + +#include "FMWKInterface.h" + +namespace supera { + + /** + \class ParamsChStatus + User defined class ParamsChStatus ... these comments are used to generate + doxygen documentation! + */ + class ParamsChStatus { + + public: + + /// Default constructor + ParamsChStatus() {} + + /// Default destructor + ~ParamsChStatus(){} + + void configure(const supera::Config_t&); + + // + // Getter + // + const std::string& OutChStatusLabel() const { return _out_chstatus_producer; } + + private: + + std::string _out_chstatus_producer; + + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/ParamsImage2D.cxx b/ParamsImage2D.cxx new file mode 100644 index 0000000..6506a11 --- /dev/null +++ b/ParamsImage2D.cxx @@ -0,0 +1,13 @@ +#ifndef __SUPERAPARAMSIMAGE2D_CXX__ +#define __SUPERAPARAMSIMAGE2D_CXX__ + +#include "ParamsImage2D.h" + +namespace supera { + + void ParamsImage2D::configure(const supera::Config_t& cfg) + { + _out_image_producer = cfg.get("OutImageLabel",""); + } +} +#endif diff --git a/ParamsImage2D.h b/ParamsImage2D.h new file mode 100644 index 0000000..e4f1964 --- /dev/null +++ b/ParamsImage2D.h @@ -0,0 +1,52 @@ +/** + * \file ParamsImage2D.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class ParamsImage2D + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAPARAMSIMAGE2D_H__ +#define __SUPERAPARAMSIMAGE2D_H__ + +#include "FMWKInterface.h" + +namespace supera { + + /** + \class ParamsImage2D + User defined class ParamsImage2D ... these comments are used to generate + doxygen documentation! + */ + class ParamsImage2D { + + public: + + /// Default constructor + ParamsImage2D() {} + + /// Default destructor + ~ParamsImage2D(){} + + void configure(const supera::Config_t&); + + // + // Getter + // + const std::string& OutImageLabel() const { return _out_image_producer; } + + private: + + std::string _out_image_producer; + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/ParamsPixel2D.cxx b/ParamsPixel2D.cxx new file mode 100644 index 0000000..030fe42 --- /dev/null +++ b/ParamsPixel2D.cxx @@ -0,0 +1,13 @@ +#ifndef __SUPERAPARAMS_PIXEL2D_CXX__ +#define __SUPERAPARAMS_PIXEL2D_CXX__ + +#include "ParamsPixel2D.h" + +namespace supera { + + void ParamsPixel2D::configure(const supera::Config_t& cfg) + { + _out_pixel2d_producer = cfg.get("OutPixel2DLabel", ""); + } +} +#endif diff --git a/ParamsPixel2D.h b/ParamsPixel2D.h new file mode 100644 index 0000000..a74b772 --- /dev/null +++ b/ParamsPixel2D.h @@ -0,0 +1,53 @@ +/** + * \file ParamsPixel2D.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class ParamsPixel2D + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAPARAMS_PIXEL2D_H__ +#define __SUPERAPARAMS_PIXEL2D_H__ + +#include "FMWKInterface.h" + +namespace supera { + + /** + \class ParamsPixel2D + User defined class ParamsPixel2D ... these comments are used to generate + doxygen documentation! + */ + class ParamsPixel2D { + + public: + + /// Default constructor + ParamsPixel2D() {} + + /// Default destructor + ~ParamsPixel2D(){} + + void configure(const supera::Config_t&); + + // + // Getter + // + const std::string& OutPixel2DLabel() const { return _out_pixel2d_producer; } + + private: + + std::string _out_pixel2d_producer; + + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/ParamsROI.cxx b/ParamsROI.cxx new file mode 100644 index 0000000..b12843f --- /dev/null +++ b/ParamsROI.cxx @@ -0,0 +1,13 @@ +#ifndef __SUPERAPARMSROI_CXX__ +#define __SUPERAPARMSROI_CXX__ + +#include "ParamsROI.h" + +namespace supera { + + void ParamsROI::configure(const supera::Config_t& cfg) + { + _out_roi_producer = cfg.get("OutROILabel",""); + } +} +#endif diff --git a/ParamsROI.h b/ParamsROI.h new file mode 100644 index 0000000..420d431 --- /dev/null +++ b/ParamsROI.h @@ -0,0 +1,53 @@ +/** + * \file ParamsROI.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class ParamsROI + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAPARAMSROI_H__ +#define __SUPERAPARAMSROI_H__ + +#include "FMWKInterface.h" + +namespace supera { + + /** + \class ParamsROI + User defined class ParamsROI ... these comments are used to generate + doxygen documentation! + */ + class ParamsROI { + + public: + + /// Default constructor + ParamsROI() {} + + /// Default destructor + ~ParamsROI(){} + + void configure(const supera::Config_t&); + + // + // Getter + // + const std::string& OutROILabel() const { return _out_roi_producer; } + + private: + + std::string _out_roi_producer; + + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/ParamsVoxel3D.cxx b/ParamsVoxel3D.cxx new file mode 100644 index 0000000..bfb671f --- /dev/null +++ b/ParamsVoxel3D.cxx @@ -0,0 +1,13 @@ +#ifndef __SUPERAPARAMSVOXEL3D_CXX__ +#define __SUPERAPARAMSVOXEL3D_CXX__ + +#include "ParamsVoxel3D.h" + +namespace supera { + + void ParamsVoxel3D::configure(const supera::Config_t& cfg) + { + _out_voxel3d_producer = cfg.get("OutVoxel3DLabel", ""); + } +} +#endif diff --git a/ParamsVoxel3D.h b/ParamsVoxel3D.h new file mode 100644 index 0000000..9482f42 --- /dev/null +++ b/ParamsVoxel3D.h @@ -0,0 +1,53 @@ +/** + * \file ParamsVoxel3D.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class ParamsVoxel3D + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAPARAMSVOXEL3D_H__ +#define __SUPERAPARAMSVOXEL3D_H__ + +#include "FMWKInterface.h" + +namespace supera { + + /** + \class ParamsVoxel3D + User defined class ParamsVoxel3D ... these comments are used to generate + doxygen documentation! + */ + class ParamsVoxel3D { + + public: + + /// Default constructor + ParamsVoxel3D() {} + + /// Default destructor + ~ParamsVoxel3D(){} + + void configure(const supera::Config_t&); + + // + // Getter + // + const std::string& OutVoxel3DLabel() const { return _out_voxel3d_producer; } + + private: + + std::string _out_voxel3d_producer; + + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/PulledPork3DSlicer.cxx b/PulledPork3DSlicer.cxx new file mode 100644 index 0000000..f93a271 --- /dev/null +++ b/PulledPork3DSlicer.cxx @@ -0,0 +1,389 @@ +#ifndef __PULLEDPORK3DSLICER_CXX__ +#define __PULLEDPORK3DSLICER_CXX__ + +#include "PulledPork3DSlicer.h" +#include "LAr2Image.h" +#include "larcv/core/DataFormat/EventImage2D.h" +//#include "larcv/core/DataFormat/DataFormatUtil.h" +#include + +namespace supera { + + void PulledPork3DSlicer::configure(const supera::Config_t& cfg) + { + set_verbosity((larcv::msg::Level_t)(cfg.get("Verbosity",logger().level()))); + _slicer.Verbosity((unsigned int)(logger().level())); + + LARCV_INFO() << std::endl; + ImageMetaMakerBase::configure(cfg); + + _origin = cfg.get("Origin",0); + _slicer.Clear(); + LARCV_INFO() << std::endl; + // Set the grid size by minimum wire spacing + double grid_size_ymin = std::numeric_limits::max(); + double grid_size_zmin = std::numeric_limits::max(); + for(size_t plane=0; plane::max(); + double grid_size_z = std::numeric_limits::max(); + if(angle == 0) { + grid_size_y = supera::WirePitch(plane); + }else if(angle == 90){ + grid_size_z = supera::WirePitch(plane); + }else { + grid_size_y = std::fabs(supera::WirePitch(plane) / cos((double)(angle) / 180. * M_PI)); + grid_size_z = std::fabs(grid_size_y / tan((double)(angle) / 180. * M_PI)); + } + if(grid_size_y < grid_size_ymin) grid_size_ymin = grid_size_y; + if(grid_size_z < grid_size_zmin) grid_size_zmin = grid_size_z; + } + _slicer.SetGridSize(supera::DriftVelocity()*supera::TPCTickPeriod(),grid_size_ymin,grid_size_zmin); + // Target volume size + auto width_v = cfg.get >("WidthArray"); + if(width_v.size()!=3) { + LARCV_CRITICAL() << "Must provide WidthArray of size 3 for xyz width" << std::endl; + throw std::exception(); + } + if(width_v[0] < _slicer.GridSizeX()) { + LARCV_CRITICAL() << "X width is smaller than grid size!" << std::endl; + throw std::exception(); + } + if(width_v[1] < _slicer.GridSizeY()) { + LARCV_CRITICAL() << "Y width is smaller than grid size!" << std::endl; + throw std::exception(); + } + if(width_v[2] < _slicer.GridSizeZ()) { + LARCV_CRITICAL() << "Z width is smaller than grid size!" << std::endl; + throw std::exception(); + } + _slicer.SetWidth(width_v[0],width_v[1],width_v[2]); + // Fiducial volume min + auto min_pt = cfg.get >("MinCoordinate"); + if(min_pt.size() != 3) { + LARCV_CRITICAL() << "Must provide MinCoordinate of size 3 for xyz min. point" << std::endl; + throw std::exception(); + } + auto max_pt = cfg.get >("MaxCoordinate"); + if(max_pt.size() != 3) { + LARCV_CRITICAL() << "Must provide MaxCoordinate of size 3 for xyz max. point" << std::endl; + throw std::exception(); + } + for(size_t i=0; i<3; ++i) { + if(min_pt[i] < max_pt[i]) continue; + LARCV_CRITICAL() << "MinCoordinate exceeds MaxCoordinate for coordinate index " << i << std::endl; + throw std::exception(); + } + _slicer.SetMin(min_pt[0],min_pt[1],min_pt[2]); + _slicer.SetMax(max_pt[0],max_pt[1],max_pt[2]); + + // Padding + auto padding_v = cfg.get >("Padding"); + if(padding_v.size() != 3) { + LARCV_CRITICAL() << "Must provide Padding of size 3 for xyz max. point" << std::endl; + throw std::exception(); + } + _slicer.SetPadding(padding_v[0] * _slicer.GridSizeX(), + padding_v[1] * _slicer.GridSizeY(), + padding_v[2] * _slicer.GridSizeZ()); + + // Artificial constraint + std::vector constraint_xv, constraint_yv, constraint_zv; + constraint_xv = cfg.get > ("ConstraintX",constraint_xv); + constraint_yv = cfg.get > ("ConstraintY",constraint_yv); + constraint_zv = cfg.get > ("ConstraintZ",constraint_zv); + if(constraint_xv.size() != constraint_yv.size() || + constraint_xv.size() != constraint_zv.size()) { + LARCV_CRITICAL() << "Constraint XYZ does not match in size..." << std::endl; + throw std::exception(); + } + for(size_t i=0; i("TimePixels"); + + // Target wire pixels + _wire_pixel_v = cfg.get >("WirePixels"); + if(_wire_pixel_v.size()!=supera::Nplanes()) { + LARCV_CRITICAL() << "WirePixels parameter array length != # planes..." << std::endl; + throw std::exception(); + } + + // Apply SCE + _apply_sce = cfg.get("ApplySCE"); + + // T0 in G4 time + _t0_g4ns = cfg.get("T0G4ns"); + + LARCV_NORMAL() << _slicer.PrintConfig() << std::flush; + + supera::GridPoint3D tmp_min_pt; + supera::GridPoint3D tmp_max_pt; + std::vector tmp_point_v; + _slicer.DeriveRange(tmp_point_v,tmp_min_pt,tmp_max_pt); + + if(!this->Test()) { + LARCV_CRITICAL() << "Meta test generation failed @ configuration end..." << std::endl; + throw std::exception(); + } + + } + + bool PulledPork3DSlicer::Test() const + { + // Test by adding fake points @ middle + std::vector points_v; + auto meta_v = DeriveMeta(points_v,0); + + if(meta_v.size() != supera::Nplanes()) + LARCV_CRITICAL() << "Failed on test meta generation!" << std::endl; + else + LARCV_NORMAL() << "Generated test meta..." << std::endl; + for(auto const& meta : meta_v) + LARCV_NORMAL() << meta.dump() << std::flush; + + return (meta_v.size() == supera::Nplanes()); + } + + void PulledPork3DSlicer::AddConstraint(double x, double y, double z) + { _slicer.AddConstraint(x,y,z); } + + void PulledPork3DSlicer::AddConstraint(const std::vector& mctruth_v) { + for(auto const& mct : mctruth_v) + this->AddConstraint(mct); + } + + void PulledPork3DSlicer::AddConstraint(const supera::LArMCTruth_t& mctruth) { + + if(_origin > 0 && mctruth.Origin() != _origin) { + LARCV_INFO() << "Skipping to add a constraint for origin " << mctruth.Origin() + << " (target " << _origin << ")" << std::endl; + return; + } + + LARCV_INFO() << "Searching for a constraint from " << mctruth.NParticles() + << " particles in one MCTruth..." << std::endl; + for(int i=0; i& simch_v, + const int time_offset) + { + std::vector trackid_v; + GenerateMeta(simch_v,time_offset,trackid_v,false); + } + + void PulledPork3DSlicer::GenerateMeta(const std::vector& simch_v, + const int time_offset, + const std::vector& trackid_v) + { GenerateMeta(simch_v,time_offset,trackid_v,true); } + + void PulledPork3DSlicer::GenerateMeta(const std::vector& simch_v, + const int time_offset, + const std::vector& trackid_v, + const bool use_track_id) + { + LARCV_INFO() << _slicer.PrintConfig() << std::flush; + + // Retrieve boundaries + auto const& min_grid = _slicer.EffectiveMin(); + auto const& max_grid = _slicer.EffectiveMax(); + + // Get xyz range: note, this is NOT A POINT, don't apply SCE + // (if _apply_sce is true, this region already takes that into account) + double xmax = max_grid.x * _slicer.GridSizeX(); + double ymax = max_grid.y * _slicer.GridSizeY(); + double zmax = max_grid.z * _slicer.GridSizeZ(); + double xmin = min_grid.x * _slicer.GridSizeX(); + double ymin = min_grid.y * _slicer.GridSizeY(); + double zmin = min_grid.z * _slicer.GridSizeZ(); + + // Convenient conversion factor + const double tdc2x = supera::TPCTickPeriod() * supera::DriftVelocity(); + // Being lazy, use std::set for a unique set of points + std::set point_s; + // Loop over sim channel and register relevant points + for (auto const& sch : simch_v) { + for (auto const tdc_ides : sch.TDCIDEMap()) { + + // Check tdc: this is effectively checking X in image coordinate + double xpos = (tdc_ides.first - supera::TPCG4Time2TDC(_t0_g4ns)) * tdc2x; + if(xpos < xmin || xpos > xmax) continue; + + for(auto const& edep : tdc_ides.second) { + // Check y/z + if(edep.y < ymin || edep.y > ymax) continue; + if(edep.z < zmin || edep.z > zmax) continue; + if(use_track_id && + std::abs(edep.trackID) < trackid_v.size() && + trackid_v[std::abs(edep.trackID)] <=0) + continue; + // Register + point_s.insert(_slicer.GridPoint3D(xpos,edep.y,edep.z)); + } + } + } + + // Now derive range + std::vector point_v; + point_v.reserve(point_s.size()); + for(auto const& pt : point_s) point_v.push_back(pt); + + _meta_v = DeriveMeta(point_v,time_offset); + } + + void PulledPork3DSlicer::GenerateMeta(const int time_offset) + { + LARCV_INFO() << _slicer.PrintConfig() << std::flush; + std::vector point_v; + _meta_v = DeriveMeta(point_v,time_offset); + } + + std::vector + PulledPork3DSlicer::DeriveMeta(const std::vector& point_v, + const int time_offset) const { + + supera::GridPoint3D min_pt; + supera::GridPoint3D max_pt; + _slicer.DeriveRange(point_v,min_pt,max_pt); + + std::vector > edge_v(4,std::vector(3,0.)); + edge_v[0][1] = min_pt.y * _slicer.GridSizeY(); + edge_v[0][2] = min_pt.z * _slicer.GridSizeZ(); + edge_v[1][1] = min_pt.y * _slicer.GridSizeY(); + edge_v[1][2] = max_pt.z * _slicer.GridSizeZ(); + edge_v[2][1] = max_pt.y * _slicer.GridSizeY(); + edge_v[2][2] = max_pt.z * _slicer.GridSizeZ(); + edge_v[3][1] = max_pt.y * _slicer.GridSizeY(); + edge_v[3][2] = min_pt.z * _slicer.GridSizeZ(); + + // Figure out wire range + std::vector > wire_range_v(supera::Nplanes()); + for(auto& wire_range : wire_range_v) { + wire_range.first = std::numeric_limits::max(); + wire_range.second = std::numeric_limits::min(); + } + for(auto const& edge_pt : edge_v) { + for(size_t plane=0; plane wire_range.second) wire_range.second = wire; + } + } + // Clean up edge effects + for(size_t plane=0; plane " << wire_range.second + << " good match for expected pixel count " << pixel_count + << std::endl; + }else{ + LARCV_WARNING() << "Plane " << plane + << " wire range " << wire_range.first + << " => " << wire_range.second + << " does not match exactly for expected pixel count " << pixel_count + << std::endl; + } + // If pixel count does not match exactly, extend + if(pixel_count_offset > 0) { + bool extend_to_lower = ( wire_range.first > ((int)(supera::Nwires(plane)) - wire_range.second) ); + if(extend_to_lower) + wire_range.first -= pixel_count_offset; + else + wire_range.second += pixel_count_offset; + } + if(pixel_count_offset < 0) { + bool shrink_from_lower = ( wire_range.first > ((int)(supera::Nwires(plane)) - wire_range.second) ); + if(shrink_from_lower) + wire_range.first -= pixel_count_offset; + else + wire_range.second += pixel_count_offset; + } + } + + // Tick conversion from X + //int tick_start = (int)((min_pt.x / supera::DriftVelocity() - supera::TriggerOffsetTPC()) / supera::TPCTickPeriod() + 0.5) + time_offset; + //int tick_end = (int)((max_pt.x / supera::DriftVelocity() - supera::TriggerOffsetTPC()) / supera::TPCTickPeriod() + 0.5) + time_offset; + int tick_start = min_pt.x + time_offset - supera::TriggerOffsetTPC() / supera::TPCTickPeriod(); + int tick_end = max_pt.x + time_offset - supera::TriggerOffsetTPC() / supera::TPCTickPeriod(); + + LARCV_INFO() << "X range: " << min_pt.x << " => " << max_pt.x + << " converted to " << tick_start << " => " << tick_end << std::endl; + + // Clean up edge effect + int tick_count_offset = _time_pixel - (tick_end - tick_start + 1); + if( std::abs(tick_count_offset) > 1 ) { + LARCV_CRITICAL() << "Time tick range " << tick_start + << " => " << tick_end + << " does not match expected pixel count " << _time_pixel << std::endl; + throw std::exception(); + } + if( tick_count_offset>0 ) tick_end -= tick_count_offset; + if( tick_count_offset<0 ) tick_end += tick_count_offset; + + std::vector meta_v; + for(size_t plane=0; planename() == "PulledPork3DSlicer"); } + + void configure(const supera::Config_t&); + + void AddConstraint(double x, double y, double z); + + void AddConstraint(const supera::LArMCTruth_t& mctruth); + + void AddConstraint(const std::vector& mctruth_v); + + void + GenerateMeta(const std::vector& simch_v, + const int time_offset); + + void + GenerateMeta(const std::vector& simch_v, + const int time_offset, + const std::vector& trackid_v); + + void + GenerateMeta(const int time_offset); + + void ClearEventData(); + + bool Test() const; + + inline const std::vector& Meta() const + { return _meta_v;} + + private: + + unsigned short _origin; + std::vector _wire_pixel_v; + supera::WireRange3D _slicer; + bool _apply_sce; + size_t _time_pixel; + double _t0_g4ns; + std::vector _meta_v; + + std::vector + DeriveMeta(const std::vector& point_v, + const int time_offset ) const; + + void + GenerateMeta(const std::vector& simch_v, + const int time_offset, + const std::vector& trackid_v, + const bool use_track_id); + }; + +} +#endif +/** @} */ // end of doxygen group + diff --git a/RSEFilter_module.cc b/RSEFilter_module.cc new file mode 100644 index 0000000..f1ddc9c --- /dev/null +++ b/RSEFilter_module.cc @@ -0,0 +1,76 @@ +//////////////////////////////////////////////////////////////////////// +// Class: RSEFilter +// Module Type: filter +// File: RSEFilter_module.cc +// +// Generated at Fri Jul 28 01:52:57 2017 by Kazuhiro Terao using artmod +// from cetpkgsupport v1_11_00. +//////////////////////////////////////////////////////////////////////// + +#include "art/Framework/Core/EDFilter.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +//#include "art/Utilities/InputTag.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" + +#include +#include +#include +#include + +#include "SuperaCSVReader.h" + +class RSEFilter; + +class RSEFilter : public art::EDFilter { +public: + explicit RSEFilter(fhicl::ParameterSet const & p); + // The destructor generated by the compiler is fine for classes + // without bare pointers or other resource use. + + // Plugins should not be copied or assigned. + RSEFilter(RSEFilter const &) = delete; + RSEFilter(RSEFilter &&) = delete; + RSEFilter & operator = (RSEFilter const &) = delete; + RSEFilter & operator = (RSEFilter &&) = delete; + + // Required functions. + bool filter(art::Event & e) override; + + +private: + + // Declare member data here. + std::map > _event_m; +}; + + +RSEFilter::RSEFilter(fhicl::ParameterSet const & p) +{ + + std::string runlist; + + //cet::search_path finder("FHICL_FILE_PATH"); + cet::search_path finder("FW_SEARCH_PATH"); + + if( !finder.find_file(p.get("CSVName"),runlist) ) + throw cet::exception("LArSoftSuperaSriver") << "Unable to find supera cfg in " << finder.to_string() << "\n"; + + supera::csvreader::read_constraint_file(runlist, _event_m); +} + +bool RSEFilter::filter(art::Event & e) +{ + int run = e.id().run(); + int subrun = e.id().subRun(); + int event = e.id().event(); + + supera::RSEID id(run,subrun,event); + return _event_m.find(id) != _event_m.end(); +} + +DEFINE_ART_MODULE(RSEFilter) diff --git a/Range.cxx b/Range.cxx new file mode 100644 index 0000000..dd63d52 --- /dev/null +++ b/Range.cxx @@ -0,0 +1,7 @@ +#ifndef __LARCVUTIL_RANGE_CXX__ +#define __LARCVUTIL_RANGE_CXX__ + +#include "Range.h" + + +#endif diff --git a/Range.h b/Range.h new file mode 100644 index 0000000..8fadb35 --- /dev/null +++ b/Range.h @@ -0,0 +1,145 @@ +/** + * \file Range.h + * + * \ingroup Utils + * + * \brief Class def header for a class Range + * + * @author kazuhiro + */ + +/** \addtogroup Utils + @{*/ +#ifndef __LARCVUTIL_RANGE_H__ +#define __LARCVUTIL_RANGE_H__ + +#include +#include +#include + +namespace larcv { + + template + class UniqueRangeSet; + + /** + \class Range + @brief represents a "Range" w/ notion of ordering. + A range is defined by a pair of "start" and "end" values. This is stored in std::pair \n + attribute larcv::Range::_window. This attribute is protected so that the start/end cannot \n + be changed w/o a check that start is always less than end. Note the specialization \n + requires a template class T to have less operator implemented. \n + */ + template + class Range { + // Make it a friend so UniqueRangeSet can access protected guys + friend class UniqueRangeSet; + + public: + /// Default ctor + Range() : _valid(false) + {} + + /// Enforced ctor. start must be less than end. + Range(const T& start, + const T& end) + : _window(start,end) + , _valid(true) + { if(start>end) throw std::runtime_error("Inserted invalid range: end before start."); } + + /// Default dtor + ~Range(){} + + /// validity + bool valid() const { return _valid; } + /// "start" accessor + const T& Start() const { return _window.first; } + /// "end" accessor + const T& End() const { return _window.second; } + /// Setter + void Set(const T& s, const T& e) + { + if(s>e) throw std::runtime_error("Inserted invalid range: end before start."); + _window.first = s; + _window.second = e; + _valid = true; + } + /// Checker (if value is inside range or not) + inline bool Inside(const T& v) const + { return _window.first <= v && v <= _window.second; } + /// Checker (if value is outside range or not) + inline bool Outside(const T& v) const + { return !(this->Inside(v)); } + + // + // Ordering w/ another Range + // + inline bool operator< (const Range& rhs) const + {return ( _window.second < rhs.Start() ); } + inline bool operator> (const Range& rhs) const + {return ( _window.first > rhs.End() ); } + inline bool operator==(const Range& rhs) const + {return ( _window.first == rhs.Start() && _window.second == rhs.End() ); } + inline bool operator!=(const Range& rhs) const + {return !( (*this) == rhs ); } + + // + // Ordering w/ T + // + inline bool operator< (const T& rhs) const + {return (_window.second < rhs); } + inline bool operator> (const T& rhs) const + {return (_window.first > rhs); } + + /// Merge two larcv::Range into 1 + inline Range operator+ (const Range& rhs) const + { + Range res(*this); + res.Set(std::min( _window.first, rhs.Start() ), + std::max( _window.second, rhs.End() ) ); + return res; + } + inline Range& operator+= (const Range& rhs) + { + _window.first = std::min( _window.first, rhs.Start() ); + _window.second = std::max( _window.second, rhs.End() ); + return (*this); + } + inline Range& operator+= (const T& rhs) + { + _window.first = std::min( _window.first, rhs ); + _window.second = std::max( _window.second, rhs ); + return (*this); + } + + /* + void Merge(const Range& a) { + _window.first = std::min( _window.first, a.Start() ); + _window.second = std::max( _window.second, a.End() ); + } + */ + protected: + /// Protected to avoid user's illegal modification on first/second (sorry users!) + std::pair _window; + /// For validity + bool _valid; + }; +} + +namespace std { + // Implement pointer comparison in case it's useful + template + /** + \class less + Implementation of std::less for larcv::Range pointers + */ + class less*> + { + public: + bool operator()( const larcv::Range* lhs, const larcv::Range* rhs ) + { return (*lhs) < (*rhs); } + }; +} + +#endif +/** @} */ // end of doxygen group diff --git a/SuperaBase.cxx b/SuperaBase.cxx new file mode 100644 index 0000000..6e0f17f --- /dev/null +++ b/SuperaBase.cxx @@ -0,0 +1,143 @@ +#ifndef __SUPERABASE_CXX__ +#define __SUPERABASE_CXX__ + +#include "SuperaBase.h" + +namespace larcv { + + static SuperaBaseProcessFactory __global_SuperaBaseProcessFactory__; + + SuperaBase::SuperaBase(const std::string name) + : ProcessBase(name) + , _empty_string() + { ClearEventData(); } + + void SuperaBase::Request(supera::LArDataType_t type, std::string name) + { _data_request_m[type]=name; } + + const std::string& SuperaBase::LArDataLabel(supera::LArDataType_t type) const + { + auto iter = _data_request_m.find(type); + if(iter == _data_request_m.end()) return _empty_string; + return (*iter).second; + } + + void SuperaBase::configure(const PSet& cfg) + { + _time_offset = cfg.get("TimeOffset",2400); + + auto producer_wire = cfg.get("LArWireProducer", ""); + auto producer_hit = cfg.get("LArHitProducer", ""); + auto producer_opdigit = cfg.get("LArOpDigitProducer", ""); + auto producer_mctruth = cfg.get("LArMCTruthProducer", ""); + auto producer_mctrack = cfg.get("LArMCTrackProducer", ""); + auto producer_mcshower = cfg.get("LArMCShowerProducer",""); + auto producer_simch = cfg.get("LArSimChProducer", ""); + + if(!producer_wire.empty() ) { + LARCV_INFO() << "Requesting Wire data product by " << producer_wire << std::endl; + Request(supera::LArDataType_t::kLArWire_t, producer_wire); + } + + if(!producer_hit.empty() ) { + LARCV_INFO() << "Requesting Hit data product by " << producer_hit << std::endl; + Request(supera::LArDataType_t::kLArHit_t, producer_hit); + } + + if(!producer_opdigit.empty() ) { + LARCV_INFO() << "Requesting OpDigit data product by " << producer_opdigit << std::endl; + Request(supera::LArDataType_t::kLArOpDigit_t, producer_opdigit ); + } + + if(!producer_mctruth.empty() ) { + LARCV_INFO() << "Requesting MCTruth data product by " << producer_mctruth << std::endl; + Request(supera::LArDataType_t::kLArMCTruth_t, producer_mctruth ); + } + + if(!producer_mctrack.empty() ) { + LARCV_INFO() << "Requesting MCTrack data product by " << producer_mctrack << std::endl; + Request(supera::LArDataType_t::kLArMCTrack_t, producer_mctrack ); + } + + if(!producer_mcshower.empty()) { + LARCV_INFO() << "Requesting MCShower data product by " << producer_mcshower << std::endl; + Request(supera::LArDataType_t::kLArMCShower_t, producer_mcshower); + } + + if(!producer_simch.empty() ) { + LARCV_INFO() << "Requesting SimCh data product by " << producer_simch << std::endl; + Request(supera::LArDataType_t::kLArSimCh_t, producer_simch); + } + + } + + void SuperaBase::initialize() + {ClearEventData();} + + bool SuperaBase::process(IOManager& mgr) + { return true; } + + void SuperaBase::finalize() + {ClearEventData();} + + bool SuperaBase::is(const std::string question) const + { + if(question == "Supera") return true; + return false; + } + + void SuperaBase::ClearEventData() + { + _ptr_wire_v = nullptr; + _ptr_hit_v = nullptr; + _ptr_opdigit_v = nullptr; + _ptr_sch_v = nullptr; + _ptr_mctruth_v = nullptr; + _ptr_mct_v = nullptr; + _ptr_mcs_v = nullptr; + } + + template <> const std::vector& SuperaBase::LArData() const + { if(!_ptr_wire_v) throw larbys("Wire data pointer not available"); return *_ptr_wire_v; } + + template <> const std::vector& SuperaBase::LArData() const + { if(!_ptr_hit_v) throw larbys("Hit data pointer not available"); return *_ptr_hit_v; } + + template <> const std::vector& SuperaBase::LArData() const + { if(!_ptr_opdigit_v) throw larbys("OpDigit data pointer not available"); return *_ptr_opdigit_v; } + + template <> const std::vector& SuperaBase::LArData() const + { if(!_ptr_sch_v) throw larbys("SimCh data pointer not available"); return *_ptr_sch_v; } + + template <> const std::vector& SuperaBase::LArData() const + { if(!_ptr_mctruth_v) throw larbys("MCTruth data pointer not available"); return *_ptr_mctruth_v; } + + template <> const std::vector& SuperaBase::LArData() const + { if(!_ptr_mct_v) throw larbys("MCTrack data pointer not available"); return *_ptr_mct_v; } + + template <> const std::vector& SuperaBase::LArData() const + { if(!_ptr_mcs_v) throw larbys("MCShower data pointer not available"); return *_ptr_mcs_v; } + + template <> void SuperaBase::LArData(const std::vector& data_v) + { _ptr_wire_v = (std::vector*)(&data_v); } + + template <> void SuperaBase::LArData(const std::vector& data_v) + { _ptr_hit_v = (std::vector*)(&data_v); } + + template <> void SuperaBase::LArData(const std::vector& data_v) + { _ptr_opdigit_v = (std::vector*)(&data_v); } + + template <> void SuperaBase::LArData(const std::vector& data_v) + { _ptr_mctruth_v = (std::vector*)(&data_v); } + + template <> void SuperaBase::LArData(const std::vector& data_v) + { _ptr_mct_v = (std::vector*)(&data_v); } + + template <> void SuperaBase::LArData(const std::vector& data_v) + { _ptr_mcs_v = (std::vector*)(&data_v); } + + template <> void SuperaBase::LArData(const std::vector& data_v) + { _ptr_sch_v = (std::vector*)(&data_v); } + +} +#endif diff --git a/SuperaBase.h b/SuperaBase.h new file mode 100644 index 0000000..8f08c6a --- /dev/null +++ b/SuperaBase.h @@ -0,0 +1,140 @@ +/** + * \file SuperaBase.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaBase + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERABASE_H__ +#define __SUPERABASE_H__ + +#include "larcv/core/Processor/ProcessBase.h" +#include "larcv/core/Processor/ProcessFactory.h" +#include "larcv/core/DataFormat/ImageMeta.h" +#include "FMWKInterface.h" +#include "SuperaTypes.h" +#include "ImageMetaMakerBase.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaBase ... these comments are used to generate + doxygen documentation! + */ + class SuperaBase : public ProcessBase { + + public: + + /// Default constructor + SuperaBase(const std::string name="SuperaBase"); + + /// Default destructor + ~SuperaBase(){} + + virtual void configure(const PSet&); + + virtual void initialize(); + + virtual bool process(IOManager& mgr); + + virtual void finalize(); + + virtual bool is(const std::string question) const; + + void Request(supera::LArDataType_t, std::string); + + template + void LArData(const T&); + + inline void SetCSV(const std::string& fname) + { _csv_fname = fname; } + + void ClearEventData(); + + // + // Getter + // + const std::string& LArDataLabel(supera::LArDataType_t type) const; + + template + const std::vector& LArData() const; + + int TimeOffset() const { return _time_offset; } + + const std::string& CSV() const { return _csv_fname; } + + private: + + std::string _empty_string; + int _time_offset; + std::map _data_request_m; + std::vector* _ptr_wire_v; + std::vector* _ptr_hit_v; + std::vector* _ptr_opdigit_v; + std::vector* _ptr_sch_v; + std::vector* _ptr_mctruth_v; + std::vector* _ptr_mct_v; + std::vector* _ptr_mcs_v; + std::string _csv_fname; + }; + + // + // Pointer getter/setters (templated) + // + + template <> const std::vector& SuperaBase::LArData() const; + + template <> const std::vector& SuperaBase::LArData() const; + + template <> const std::vector& SuperaBase::LArData() const; + + template <> const std::vector& SuperaBase::LArData() const; + + template <> const std::vector& SuperaBase::LArData() const; + + template <> const std::vector& SuperaBase::LArData() const; + + template <> const std::vector& SuperaBase::LArData() const; + + template <> void SuperaBase::LArData(const std::vector& data_v); + + template <> void SuperaBase::LArData(const std::vector& data_v); + + template <> void SuperaBase::LArData(const std::vector& data_v); + + template <> void SuperaBase::LArData(const std::vector& data_v); + + template <> void SuperaBase::LArData(const std::vector& data_v); + + template <> void SuperaBase::LArData(const std::vector& data_v); + + template <> void SuperaBase::LArData(const std::vector& data_v); + + /** + \class larcv::SuperaBaseFactory + \brief A concrete factory class for larcv::SuperaBase + */ + class SuperaBaseProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaBaseProcessFactory() { ProcessFactory::get().add_factory("SuperaBase",this); } + /// dtor + ~SuperaBaseProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaBase(instance_name); } + }; + + + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/SuperaCSVReader.h b/SuperaCSVReader.h new file mode 100644 index 0000000..179c31e --- /dev/null +++ b/SuperaCSVReader.h @@ -0,0 +1,66 @@ +#ifndef __SUPERACSVREADER_H__ +#define __SUPERACSVREADER_H__ +#include +#include +#include +#include +#include "SuperaTypes.h" +namespace supera { + + namespace csvreader { + + inline bool line_to_point(const std::string& line_data, + supera::RSEID& id, + std::array& point) { + size_t run, subrun, event,x,y,z; + run = subrun = event = x = y = z = 0; + try { + run = line_data.find(","); + subrun = line_data.find(",",run+1); + event = line_data.find(",",subrun+1); + x = line_data.find(",",event+1); + y = line_data.find(",",x+1); + z = line_data.find(" ",y+1); + + id.run = std::atoi(line_data.substr(0,run).c_str()); + id.subrun = std::atoi(line_data.substr(run+1,subrun-(run+1)).c_str()); + id.event = std::atoi(line_data.substr(subrun+1,event-(subrun+1)).c_str()); + point[0] = std::atof(line_data.substr(event+1,x-(event+1)).c_str()); + point[1] = std::atof(line_data.substr(x+1,y-(x+1)).c_str()); + point[2] = std::atof(line_data.substr(y+1,z-(y+1)).c_str()); + }catch(const std::exception& err) { + std::cerr << "Failed to convert: \"" << line_data << "\"" << std::endl; + return false; + } + return true; + } + + inline void read_constraint_file(std::string fname, + std::map >& data) + { + + std::ifstream fstrm(fname.c_str()); + std::string line_data; + supera::RSEID id; + std::array position; + + std::getline(fstrm, line_data); // ignore 1st line + while(std::getline(fstrm, line_data)) { + + if(line_data.empty()) continue; + + if(supera::csvreader::line_to_point(line_data,id,position)) { + + auto iter = data.find(id); + if(iter != data.end()) { + std::cerr << "Run=" << id.run << " Subrun=" << id.subrun << " Event=" << id.event << " is duplicated!" << std::endl; + throw std::exception(); + } + data[id]=position; + } + } + } + + } +} +#endif diff --git a/SuperaChStatus.cxx b/SuperaChStatus.cxx new file mode 100644 index 0000000..f331054 --- /dev/null +++ b/SuperaChStatus.cxx @@ -0,0 +1,65 @@ +#ifndef __SUPERACHSTATUS_CXX__ +#define __SUPERACHSTATUS_CXX__ + +#include "SuperaChStatus.h" +#include "larcv/core/DataFormat/EventChStatus.h" + +namespace larcv { + + static SuperaChStatusProcessFactory __global_SuperaChStatusProcessFactory__; + + SuperaChStatus::SuperaChStatus(const std::string name) + : SuperaBase(name) + {} + + void SuperaChStatus::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsChStatus::configure(cfg); + _in_chstatus_producer = cfg.get("LArChStatusProducer"); + } + + void SuperaChStatus::initialize() + { + SuperaBase::initialize(); + for (size_t i = 0; i < ::supera::Nplanes(); ++i) { + ::larcv::ChStatus status; + status.id(i); + status.initialize(::supera::Nwires(i), ::larcv::chstatus::kUNKNOWN); + _status_m.emplace(status.id(), status); + } + } + + void SuperaChStatus::set_chstatus(::larcv::ProjectionID_t plane, unsigned int wire, short status) + { + if (wire >= ::supera::Nwires(plane)) throw ::larcv::larbys("Invalid wire number to store status!"); + _status_m[plane].status(wire, status); + } + + bool SuperaChStatus::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + auto ev_chstatus = (EventChStatus*)(mgr.get_data("chstatus",OutChStatusLabel())); + if(!ev_chstatus) { + LARCV_CRITICAL() << "Output chstatus could not be created!" << std::endl; + throw larbys(); + } + + for (auto const& id_status : _status_m) + ev_chstatus->insert(id_status.second); + + // Reset status + for (auto& plane_status : _status_m) plane_status.second.reset(::larcv::chstatus::kUNKNOWN); + + return true; + } + + void SuperaChStatus::finalize() + { SuperaBase::finalize(); } + + bool SuperaChStatus::is(const std::string question) const + { return (question == "SuperaChStatus"); } + +} +#endif diff --git a/SuperaChStatus.h b/SuperaChStatus.h new file mode 100644 index 0000000..16abf18 --- /dev/null +++ b/SuperaChStatus.h @@ -0,0 +1,75 @@ +/** + * \file SuperaChStatus.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaChStatus + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERACHSTATUS_H__ +#define __SUPERACHSTATUS_H__ +#include "larcv/core/DataFormat/ChStatus.h" +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "ParamsChStatus.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaChStatus ... these comments are used to generate + doxygen documentation! + */ + class SuperaChStatus : public SuperaBase, + public supera::ParamsChStatus { + + public: + + /// Default constructor + SuperaChStatus(const std::string name="SuperaChStatus"); + + /// Default destructor + ~SuperaChStatus(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + bool is(const std::string question) const; + + void set_chstatus(::larcv::ProjectionID_t plane, unsigned int wire, short status); + + const std::string& InputLabel() const { return _in_chstatus_producer; } + + private: + std::string _in_chstatus_producer; + std::map _status_m; + }; + + /** + \class larcv::SuperaChStatusFactory + \brief A concrete factory class for larcv::SuperaChStatus + */ + class SuperaChStatusProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaChStatusProcessFactory() { ProcessFactory::get().add_factory("SuperaChStatus",this); } + /// dtor + ~SuperaChStatusProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaChStatus(instance_name); } + }; + +} +#endif +/** @} */ // end of doxygen group + diff --git a/SuperaHit.cxx b/SuperaHit.cxx new file mode 100644 index 0000000..c88d665 --- /dev/null +++ b/SuperaHit.cxx @@ -0,0 +1,72 @@ +#ifndef __SUPERAHIT_CXX__ +#define __SUPERAHIT_CXX__ + +#include "SuperaHit.h" +#include "LAr2Image.h" +#include "ImageMetaMakerFactory.h" +#include "PulledPork3DSlicer.h" +#include "larcv/core/DataFormat/EventImage2D.h" +namespace larcv { + + static SuperaHitProcessFactory __global_SuperaHitProcessFactory__; + + SuperaHit::SuperaHit(const std::string name) + : SuperaBase(name) + {} + + void SuperaHit::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsImage2D::configure(cfg); + supera::ImageMetaMaker::configure(cfg); + } + + void SuperaHit::initialize() + { SuperaBase::initialize(); } + + bool SuperaHit::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + if(supera::PulledPork3DSlicer::Is(supera::ImageMetaMaker::MetaMakerPtr())) { + auto ptr = (supera::PulledPork3DSlicer*)(supera::ImageMetaMaker::MetaMakerPtr()); + ptr->ClearEventData(); + ptr->AddConstraint(LArData()); + ptr->GenerateMeta(LArData(),TimeOffset()); + } + + auto const& meta_v = Meta(); + + if(meta_v.empty()) { + LARCV_CRITICAL() << "Meta not created!" << std::endl; + throw larbys(); + } + auto ev_image = (EventImage2D*)(mgr.get_data("image2d",OutImageLabel())); + if(!ev_image) { + LARCV_CRITICAL() << "Output image could not be created!" << std::endl; + throw larbys(); + } + if(!(ev_image->image2d_array().empty())) { + LARCV_CRITICAL() << "Output image array not empty!" << std::endl; + throw larbys(); + } + + auto image_v = supera::Hit2Image2D(meta_v, LArData(), TimeOffset()); + + for(size_t plane=0; planeemplace(std::move(image_v)); + + return true; + } + + void SuperaHit::finalize() + {SuperaBase::finalize();} + +} +#endif diff --git a/SuperaHit.h b/SuperaHit.h new file mode 100644 index 0000000..4b86f53 --- /dev/null +++ b/SuperaHit.h @@ -0,0 +1,72 @@ +/** + * \file SuperaHit.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaHit + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAHIT_H__ +#define __SUPERAHIT_H__ +//#ifndef __CINT__ +//#ifndef __CLING__ +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "ParamsImage2D.h" +#include "ImageMetaMaker.h" +#include "larcv/core/DataFormat/Image2D.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaHit ... these comments are used to generate + doxygen documentation! + */ + class SuperaHit : public SuperaBase, + public supera::ParamsImage2D, + public supera::ImageMetaMaker { + + public: + + /// Default constructor + SuperaHit(const std::string name="SuperaHit"); + + /// Default destructor + ~SuperaHit(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + }; + + /** + \class larcv::SuperaHitFactory + \brief A concrete factory class for larcv::SuperaHit + */ + class SuperaHitProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaHitProcessFactory() { ProcessFactory::get().add_factory("SuperaHit",this); } + /// dtor + ~SuperaHitProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaHit(instance_name); } + }; + +} +#endif +//#endif +//#endif +/** @} */ // end of doxygen group + diff --git a/SuperaMetaMaker.cxx b/SuperaMetaMaker.cxx new file mode 100644 index 0000000..95a1209 --- /dev/null +++ b/SuperaMetaMaker.cxx @@ -0,0 +1,74 @@ +#ifndef __SUPERAMETAMAKER_CXX__ +#define __SUPERAMETAMAKER_CXX__ + +#include "SuperaMetaMaker.h" +#include "SuperaCSVReader.h" +#include "LAr2Image.h" +#include "ImageMetaMakerFactory.h" +#include "ImageMetaMaker.h" +#include "PulledPork3DSlicer.h" +#include "larcv/core/DataFormat/EventImage2D.h" + +namespace larcv { + + static SuperaMetaMakerProcessFactory __global_SuperaMetaMakerProcessFactory__; + + SuperaMetaMaker::SuperaMetaMaker(const std::string name) + : SuperaBase(name) + , _meta_maker(nullptr) + {} + + bool SuperaMetaMaker::is(const std::string question) const + { + if(question == "Supera") return true; + if(question == "SuperaMetaMaker") return true; + return false; + } + + void SuperaMetaMaker::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + if(_meta_maker) delete _meta_maker; + _meta_maker = supera::CreateImageMetaMaker(cfg); + supera::ImageMetaMaker::SetSharedMetaMaker(_meta_maker); + } + + void SuperaMetaMaker::initialize() + { SuperaBase::initialize(); } + + bool SuperaMetaMaker::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + if(supera::PulledPork3DSlicer::Is(_meta_maker)) { + ((supera::PulledPork3DSlicer*)(_meta_maker))->ClearEventData(); + if(!LArDataLabel(supera::LArDataType_t::kLArMCTruth_t).empty()) + ((supera::PulledPork3DSlicer*)(_meta_maker))->AddConstraint(LArData()); + if(!CSV().empty() && _constraint_m.empty()) { + _constraint_m.clear(); + supera::csvreader::read_constraint_file(CSV(),_constraint_m); + LARCV_NORMAL() << "Loaded constraint points for " << _constraint_m.size() << " events..." << std::endl; + } + if(_constraint_m.size()) { + auto const& larcv_event_id = mgr.event_id(); + //supera::RSEID supera_event_id(larcv_event_id.run(),larcv_event_id.subrun(),larcv_event_id.event()); + supera::RSEID supera_event_id(larcv_event_id.run(),larcv_event_id.event()); + auto iter = _constraint_m.find(supera_event_id); + if(iter!=_constraint_m.end()) + ((supera::PulledPork3DSlicer*)(_meta_maker))->AddConstraint((*iter).second[0],(*iter).second[1],(*iter).second[2]); + } + if(!LArDataLabel(supera::LArDataType_t::kLArSimCh_t).empty()) + ((supera::PulledPork3DSlicer*)(_meta_maker))->GenerateMeta(LArData(),TimeOffset()); + else + ((supera::PulledPork3DSlicer*)(_meta_maker))->GenerateMeta(TimeOffset()); + } + + return true; + } + + void SuperaMetaMaker::finalize() + {} + + +} +#endif diff --git a/SuperaMetaMaker.h b/SuperaMetaMaker.h new file mode 100644 index 0000000..3511575 --- /dev/null +++ b/SuperaMetaMaker.h @@ -0,0 +1,70 @@ +/** + * \file SuperaMetaMaker.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaMetaMaker + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAMETAMAKER_H__ +#define __SUPERAMETAMAKER_H__ +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "ImageMetaMakerBase.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaMetaMaker ... these comments are used to generate + doxygen documentation! + */ + class SuperaMetaMaker : public SuperaBase { + + public: + + /// Default constructor + SuperaMetaMaker(const std::string name="SuperaMetaMaker"); + + /// Default destructor + ~SuperaMetaMaker(){ if(_meta_maker) delete _meta_maker; } + + bool is(const std::string question) const; + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + private: + + supera::ImageMetaMakerBase* _meta_maker; + std::map > _constraint_m; + }; + + /** + \class larcv::SuperaMetaMakerFactory + \brief A concrete factory class for larcv::SuperaMetaMaker + */ + class SuperaMetaMakerProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaMetaMakerProcessFactory() { ProcessFactory::get().add_factory("SuperaMetaMaker",this); } + /// dtor + ~SuperaMetaMakerProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaMetaMaker(instance_name); } + }; + +} +#endif +/** @} */ // end of doxygen group + diff --git a/SuperaOpDigit.cxx b/SuperaOpDigit.cxx new file mode 100644 index 0000000..17e284f --- /dev/null +++ b/SuperaOpDigit.cxx @@ -0,0 +1,75 @@ +#ifndef __SUPERAOPDIGIT_CXX__ +#define __SUPERAOPDIGIT_CXX__ + +#include "SuperaOpDigit.h" +#include "LAr2Image.h" +#include "ImageMetaMakerFactory.h" +#include "PulledPork3DSlicer.h" +#include "larcv/core/DataFormat/EventImage2D.h" + +namespace larcv { + + static SuperaOpDigitProcessFactory __global_SuperaOpDigitProcessFactory__; + + SuperaOpDigit::SuperaOpDigit(const std::string name) + : SuperaBase(name) + {} + + void SuperaOpDigit::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsImage2D::configure(cfg); + supera::ImageMetaMaker::configure(cfg); + if(supera::PulledPork3DSlicer::Is(supera::ImageMetaMaker::MetaMakerPtr())) { + LARCV_CRITICAL() << "PulledPork3DSlicer should not be used for Optical image maker!" << std::endl; + throw larbys(); + } + } + + void SuperaOpDigit::initialize() + { SuperaBase::initialize(); } + + bool SuperaOpDigit::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + auto const& meta_v = Meta(); + + if(meta_v.empty()) { + LARCV_CRITICAL() << "Meta not created!" << std::endl; + throw larbys(); + } + if(meta_v.size()!=1) { + LARCV_CRITICAL() << "Meta > 1, not expected for OpDigit" << std::endl; + throw larbys(); + } + auto ev_image = (EventImage2D*)(mgr.get_data("image2d",OutImageLabel())); + if(!ev_image) { + LARCV_CRITICAL() << "Output image could not be created!" << std::endl; + throw larbys(); + } + if(!(ev_image->image2d_array().empty())) { + LARCV_CRITICAL() << "Output image array not empty!" << std::endl; + throw larbys(); + } + + std::vector image_v; + image_v.emplace_back(supera::OpDigit2Image2D(meta_v.front(), LArData(), TimeOffset())); + + for(size_t plane=0; planeemplace(std::move(image_v)); + + return true; + } + + void SuperaOpDigit::finalize() + {} + +} +#endif diff --git a/SuperaOpDigit.h b/SuperaOpDigit.h new file mode 100644 index 0000000..faafd36 --- /dev/null +++ b/SuperaOpDigit.h @@ -0,0 +1,69 @@ +/** + * \file SuperaOpDigit.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaOpDigit + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAOPDIGIT_H__ +#define __SUPERAOPDIGIT_H__ +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "ParamsImage2D.h" +#include "ImageMetaMaker.h" +#include "larcv/core/DataFormat/Image2D.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaOpDigit ... these comments are used to generate + doxygen documentation! + */ + class SuperaOpDigit : public SuperaBase, + public supera::ParamsImage2D, + public supera::ImageMetaMaker { + + public: + + /// Default constructor + SuperaOpDigit(const std::string name="SuperaOpDigit"); + + /// Default destructor + ~SuperaOpDigit(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + }; + + /** + \class larcv::SuperaOpDigitFactory + \brief A concrete factory class for larcv::SuperaOpDigit + */ + class SuperaOpDigitProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaOpDigitProcessFactory() { ProcessFactory::get().add_factory("SuperaOpDigit",this); } + /// dtor + ~SuperaOpDigitProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaOpDigit(instance_name); } + }; + +} +#endif + +/** @} */ // end of doxygen group + diff --git a/SuperaTypes.cxx b/SuperaTypes.cxx new file mode 100644 index 0000000..74ba93a --- /dev/null +++ b/SuperaTypes.cxx @@ -0,0 +1,14 @@ +#ifndef __SUPERA_TYPES_CXX__ +#define __SUPERA_TYPES_CXX__ + +#include "SuperaTypes.h" +namespace supera { + template<> LArDataType_t LArDataType() { return LArDataType_t::kLArHit_t; } + template<> LArDataType_t LArDataType() { return LArDataType_t::kLArWire_t; } + template<> LArDataType_t LArDataType() { return LArDataType_t::kLArOpDigit_t; } + template<> LArDataType_t LArDataType() { return LArDataType_t::kLArMCTruth_t; } + template<> LArDataType_t LArDataType() { return LArDataType_t::kLArMCTrack_t; } + template<> LArDataType_t LArDataType() { return LArDataType_t::kLArMCShower_t; } + template<> LArDataType_t LArDataType() { return LArDataType_t::kLArSimCh_t; } +} +#endif diff --git a/SuperaTypes.h b/SuperaTypes.h new file mode 100644 index 0000000..5329e0c --- /dev/null +++ b/SuperaTypes.h @@ -0,0 +1,65 @@ +#ifndef __SUPERA_TYPES_H__ +#define __SUPERA_TYPES_H__ +//#ifndef __CINT__ +//#ifndef __CLING__ +#include "FMWKInterface.h" +namespace supera { + + /// enum to define LAr* data type + enum class LArDataType_t : unsigned int{ + kLArWire_t, ///< recob::Wire + kLArHit_t, ///< recob::Hit + kLArOpDigit_t, ///< raw::OpDetWaveform + kLArMCTruth_t, ///< simb::MCTruth + kLArMCTrack_t, ///< sim::MCTrack + kLArMCShower_t, ///< sim::MCShower + kLArSimCh_t, ///< sim::SimChannel + kLArDataTypeMax + }; + + template + LArDataType_t LArDataType(); + + template<> LArDataType_t LArDataType(); + template<> LArDataType_t LArDataType(); + template<> LArDataType_t LArDataType(); + template<> LArDataType_t LArDataType(); + template<> LArDataType_t LArDataType(); + template<> LArDataType_t LArDataType(); + template<> LArDataType_t LArDataType(); + + class RSEID { + public: + RSEID(size_t run_val=0, size_t subrun_val=0, size_t event_val=0) + : run(run_val) + , subrun(subrun_val) + , event(event_val) + {} + ~RSEID(){} + + inline bool operator < (const RSEID& rhs) const + { if(run < rhs.run) return true; + if(run > rhs.run) return false; + if(subrun < rhs.subrun) return true; + if(subrun > rhs.subrun) return false; + if(event < rhs.event) return true; + if(event > rhs.event) return false; + return false; + } + + inline bool operator == (const RSEID& rhs) const + { return (run == rhs.run && subrun == rhs.subrun && event == rhs.event); } + + inline bool operator != (const RSEID& rhs) const + { return !( (*this) == rhs ); } + + inline bool operator > (const RSEID& rhs) const + { return ( (*this) != rhs && !((*this) < rhs) ); } + + size_t run, subrun, event; + }; + +} +//#endif +//#endif +#endif diff --git a/SuperaWire.cxx b/SuperaWire.cxx new file mode 100644 index 0000000..a131819 --- /dev/null +++ b/SuperaWire.cxx @@ -0,0 +1,73 @@ +#ifndef __SUPERAWIRE_CXX__ +#define __SUPERAWIRE_CXX__ + +#include "SuperaWire.h" +#include "LAr2Image.h" +#include "ImageMetaMakerFactory.h" +#include "PulledPork3DSlicer.h" +#include "larcv/core/DataFormat/EventImage2D.h" + +namespace larcv { + + static SuperaWireProcessFactory __global_SuperaWireProcessFactory__; + + SuperaWire::SuperaWire(const std::string name) + : SuperaBase(name) + {} + + void SuperaWire::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsImage2D::configure(cfg); + supera::ImageMetaMaker::configure(cfg); + } + + void SuperaWire::initialize() + { SuperaBase::initialize(); } + + bool SuperaWire::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + if(supera::PulledPork3DSlicer::Is(supera::ImageMetaMaker::MetaMakerPtr())) { + auto ptr = (supera::PulledPork3DSlicer*)(supera::ImageMetaMaker::MetaMakerPtr()); + ptr->ClearEventData(); + ptr->AddConstraint(LArData()); + ptr->GenerateMeta(LArData(),TimeOffset()); + } + + auto const& meta_v = Meta(); + + if(meta_v.empty()) { + LARCV_CRITICAL() << "Meta not created!" << std::endl; + throw larbys(); + } + auto ev_image = (EventImage2D*)(mgr.get_data("image2d",OutImageLabel())); + if(!ev_image) { + LARCV_CRITICAL() << "Output image could not be created!" << std::endl; + throw larbys(); + } + if(!(ev_image->image2d_array().empty())) { + LARCV_CRITICAL() << "Output image array not empty!" << std::endl; + throw larbys(); + } + + auto image_v = supera::Wire2Image2D(meta_v, LArData(), TimeOffset()); + + for(size_t plane=0; planeemplace(std::move(image_v)); + return true; + } + + void SuperaWire::finalize() + {} + + +} +#endif diff --git a/SuperaWire.h b/SuperaWire.h new file mode 100644 index 0000000..9faec28 --- /dev/null +++ b/SuperaWire.h @@ -0,0 +1,71 @@ +/** + * \file SuperaWire.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaWire + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAWIRE_H__ +#define __SUPERAWIRE_H__ +//#ifndef __CINT__ +//#ifndef __CLING__ +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "ParamsImage2D.h" +#include "ImageMetaMaker.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaWire ... these comments are used to generate + doxygen documentation! + */ + class SuperaWire : public SuperaBase, + public supera::ParamsImage2D, + public supera::ImageMetaMaker { + + public: + + /// Default constructor + SuperaWire(const std::string name="SuperaWire"); + + /// Default destructor + ~SuperaWire(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + }; + + /** + \class larcv::SuperaWireFactory + \brief A concrete factory class for larcv::SuperaWire + */ + class SuperaWireProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaWireProcessFactory() { ProcessFactory::get().add_factory("SuperaWire",this); } + /// dtor + ~SuperaWireProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaWire(instance_name); } + }; + +} +#endif +//#endif +//#endif +/** @} */ // end of doxygen group + diff --git a/VPlaneHandler_module.cc b/VPlaneHandler_module.cc new file mode 100644 index 0000000..5333cb5 --- /dev/null +++ b/VPlaneHandler_module.cc @@ -0,0 +1,274 @@ +//////////////////////////////////////////////////////////////////////// +// Class: VPlaneHandler +// Module Type: producer +// File: VPlaneHandler_module.cc +// +// Generated at Wed May 10 08:51:17 2017 by Kazuhiro Terao using artmod +// from cetpkgsupport v1_11_00. +//////////////////////////////////////////////////////////////////////// + +#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Core/ModuleMacros.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Principal/Run.h" +#include "art/Framework/Principal/SubRun.h" +//#include "art/Utilities/InputTag.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" + +#include "lardataobj/RecoBase/Wire.h" + +#include +#include + +class VPlaneHandler; + +class VPlaneHandler : public art::EDProducer { +public: + explicit VPlaneHandler(fhicl::ParameterSet const & p); + // The destructor generated by the compiler is fine for classes + // without bare pointers or other resource use. + + // Plugins should not be copied or assigned. + VPlaneHandler(VPlaneHandler const &) = delete; + VPlaneHandler(VPlaneHandler &&) = delete; + VPlaneHandler & operator = (VPlaneHandler const &) = delete; + VPlaneHandler & operator = (VPlaneHandler &&) = delete; + + // Required functions. + void produce(art::Event & e) override; + +private: + + std::string _producer; + bool _handle_plateau; + bool _smooth; + bool _shift; + + float truncated_mean(const std::vector& data, + size_t start_idx, size_t end_idx); + + void rolling_mean(std::vector& data, + size_t start_idx, size_t end_idx); +}; + + +VPlaneHandler::VPlaneHandler(fhicl::ParameterSet const & p) +// : +// Initialize member data here. +{ + // Call appropriate produces<>() functions here. + produces< std::vector >(); + _producer = p.get("ProducerLabel"); + _handle_plateau = p.get("HandlePlateau",true); + _smooth = p.get("Smooth",true); + _shift = p.get("Shift",true); +} + +void VPlaneHandler::produce(art::Event & e) +{ + std::unique_ptr< std::vector > wire_v_ptr(new std::vector); + + art::Handle > data_h; + e.getByLabel(_producer,data_h); + if(!data_h.isValid()) + std::cout<<"\033[93m" << "Could not locate data!" << "\033[00m" << std::endl; + + for(size_t wire_idx=0; wire_idxsize(); ++wire_idx) { + + auto const& w = (*data_h)[wire_idx]; + + if( w.View() != 1 ) { + wire_v_ptr->push_back(w); + continue; + } + + auto const& roi_v = w.SignalROI().get_ranges(); + std::vector status_v(roi_v.size(),true); + for(size_t roi_idx = 0; roi_idx < roi_v.size(); ++roi_idx) { + + auto const& wf = roi_v[roi_idx].data(); + bool status = true; + size_t cont_negative = 0; + for(size_t adc_idx=1; adc_idx-5) { cont_negative = 0; continue; } + ++cont_negative; + if(cont_negative > 5) { + status = false; + break; + } + } + status_v[roi_idx] = status; + } + bool fix=false; + for(auto const& status : status_v) { + if(!status) {fix = true; break;} + } + if(!fix) { + wire_v_ptr->push_back(w); + continue; + } + + recob::Wire::RegionsOfInterest_t fixed_roi_v; + for(size_t roi_idx=0; roi_idx copy_data = orig_roi.data(); + bool negative_state=false; + bool positive_state=false; + size_t start_idx = 0; + size_t peak_idx = 0; + size_t positive_idx = 0; + size_t negative_ctr=0; // consecutive negative counter + float negative_max=0; + std::vector > flip_range_v; + for(size_t adc_idx=1; adc_idx5 && !negative_state) { + negative_state = true; + start_idx = adc_idx-5; + } + + if(negative_state && !positive_state) { + if(copy_data[adc_idx] < negative_max) { + negative_max = copy_data[adc_idx]; + peak_idx = adc_idx; + } + } + + if(negative_state && copy_data[adc_idx] > 2.0) { + if(!positive_state) positive_idx = adc_idx-1; + positive_state = true; + } + + if(positive_state && copy_data[adc_idx] < 1.5) { + std::array idxarr; + idxarr[0] = start_idx; + idxarr[1] = peak_idx; + idxarr[2] = positive_idx; + idxarr[3] = adc_idx; + flip_range_v.push_back(idxarr); + negative_state = false; + positive_state = false; + start_idx = 0; + negative_ctr = 0; + positive_idx = 0; + negative_max = 0; + peak_idx = 0; + } + } + if(negative_state) { + std::array idxarr; + idxarr[0] = start_idx; + idxarr[1] = peak_idx; + idxarr[2] = positive_idx; + idxarr[3] = copy_data.size()-1; + flip_range_v.push_back(idxarr); + } + + for(auto const& idxarr : flip_range_v) { + auto const& neg_start = idxarr[0]; + auto const& peak = idxarr[1]; + auto const& pos_start = idxarr[2]; + auto const& end = idxarr[3]; + for(size_t adc_idx=neg_start; adc_idx=(neg_start+shift)) break; + copy_copy_data[adc_idx] = 0; + } + copy_data = copy_copy_data; + } + } + fixed_roi_v.add_range(orig_roi.begin_index(),copy_data); + } + wire_v_ptr->emplace_back(recob::Wire(std::move(fixed_roi_v),w.Channel(), w.View())); + } + + e.put(std::move(wire_v_ptr)); + e.removeCachedProduct(data_h); +} + +float VPlaneHandler::truncated_mean(const std::vector& data, + size_t start_idx, size_t end_idx) +{ + float last_mean = -1.; + float mean = 0.; + float std = 0.; + std::vector skip_v(data.size(),false); + while( last_mean<0 || std::fabs(last_mean-mean) > std*1.5 ) { + last_mean = mean; + // Compute mean + float sum=0.; + float ctr=0.; + for(size_t i=start_idx; i 2*std from mean + for(size_t i=start_idx; i 2*std) skip_v[i] = true; + } + } + return mean; +} + +void VPlaneHandler::rolling_mean(std::vector& data, + size_t start_idx, size_t end_idx) +{ + size_t start, end; + if(data.size() < 9) return; + for(size_t idx=start_idx; idx<=end_idx; ++idx) { + + if(idx>=(start_idx+4)) { + if(end_idx>=(idx+4)) { + start = idx-4; + end = idx+4; + }else{ + end = end_idx; + start = end_idx-8; + } + }else{ + start = start_idx; + end = start_idx+8; + } + float mean=0; + for(size_t subidx=start; subidx<=end; ++subidx) mean += data[subidx]; + mean /= 9.; + data[idx] = mean; + } +} + +DEFINE_ART_MODULE(VPlaneHandler) diff --git a/WireRange3D.cxx b/WireRange3D.cxx new file mode 100644 index 0000000..0334486 --- /dev/null +++ b/WireRange3D.cxx @@ -0,0 +1,362 @@ +#ifndef WIRERANGE3D_CXX +#define WIRERANGE3D_CXX + +#define WIRERANGE3D_CRITICAL() if(_verbosity<6) std::cerr << " \033[5;1;33;41m[CRITICAL]\033[94m<>\033[00m " +#define WIRERANGE3D_ERROR() if(_verbosity<5) std::cerr << " \033[91m[ERROR]\033[94m <>\033[00m " +#define WIRERANGE3D_WARNING() if(_verbosity<4) std::cout << " \033[93m[WARNING]\033[94m <>\033[00m " +#define WIRERANGE3D_NORMAL() if(_verbosity<3) std::cout << " \033[95m[NORMAL]\033[94m <>\033[00m " +#define WIRERANGE3D_INFO() if(_verbosity<2) std::cout << " \033[92m[INFO]\033[94m <>\033[00m " +#define WIRERANGE3D_DEBUG() if(_verbosity<1) std::cout << " \033[94m[DEBUG]\033[94m <>\033[00m " + +#include "WireRange3D.h" +#include +#include +namespace supera { + + std::string WireRange3D::PrintConfig() const + { + std::stringstream ss; + ss << "WireRange3D configuration..." << std::endl + << " X grid size: " << _grid_size_x << " ... bounds: " << _min_fiducial.x << " => " << _max_fiducial.x + << " ... width = " << _width.x << ", padding = " << _padding.x << std::endl + << " Y grid size: " << _grid_size_y << " ... bounds: " << _min_fiducial.y << " => " << _max_fiducial.y + << " ... width = " << _width.y << ", padding = " << _padding.y << std::endl + << " Z grid size: " << _grid_size_z << " ... bounds: " << _min_fiducial.z << " => " << _max_fiducial.z + << " ... width = " << _width.z << ", padding = " << _padding.z << std::endl; + if(_constraint_v.empty()) + ss << " No constraint point registered..." << std::endl << std::endl; + else { + ss << " List of constraints:" << std::endl; + for(auto const& pt : _constraint_v) + ss << " Grid: (" << pt.x << "," << pt.y << "," << pt.z << ")" + << "... Real: (" << pt.x * GridSizeX() << "," << pt.y * GridSizeY() << "," << pt.z * GridSizeZ() << ")" << std::endl; + ss<< std::endl; + } + return std::string(ss.str()); + } + + supera::GridPoint3D WireRange3D::GridPoint3D(double x, double y, double z) const + { + if(_grid_size_x <=0. || + _grid_size_y <=0. || + _grid_size_z <=0. ) { + WIRERANGE3D_CRITICAL() << "Grid size is not set yet!" << std::endl; + throw std::exception(); + } + supera::GridPoint3D pt; + pt.x = (int)(x / _grid_size_x + 0.5); + pt.y = (int)(y / _grid_size_y + 0.5); + pt.z = (int)(z / _grid_size_z + 0.5); + return pt; + } + + bool WireRange3D::Valid() const + { + if(!_width.Valid()) return false; + if(!_min_fiducial.Valid()) return false; + if(!_max_fiducial.Valid()) return false; + if(_grid_size_x<0. || _grid_size_y<0. || _grid_size_z<0.) return false; + return true; + } + + void WireRange3D::RederiveBounds() { + _min_bound = _min_fiducial; + _max_bound = _max_fiducial; + for(auto const& constraint_pt : _constraint_v) { + if( (_min_bound.x + _width.x - _padding.x) <= constraint_pt.x ) _min_bound.x = (constraint_pt.x - _width.x + _padding.x + 1); + if( (_min_bound.y + _width.y - _padding.y) <= constraint_pt.y ) _min_bound.y = (constraint_pt.y - _width.y + _padding.y + 1); + if( (_min_bound.z + _width.z - _padding.z) <= constraint_pt.z ) _min_bound.z = (constraint_pt.z - _width.z + _padding.z + 1); + if( (_max_bound.x - _width.x + _padding.x) >= constraint_pt.x ) _max_bound.x = (constraint_pt.x + _width.x - _padding.x - 1); + if( (_max_bound.y - _width.y + _padding.y) >= constraint_pt.y ) _max_bound.y = (constraint_pt.y + _width.y - _padding.y - 1); + if( (_max_bound.z - _width.z + _padding.z) >= constraint_pt.z ) _max_bound.z = (constraint_pt.z + _width.z - _padding.z - 1); } + } + + void WireRange3D::SetPadding(double x, double y, double z) { + auto padding = this->GridPoint3D(x,y,z); + if(_constraint_v.empty()) { + _padding = padding; + return; + } + // Check if this width is compatible with registered constraints + auto min_bound = GridPoint3D(std::numeric_limits::max(),std::numeric_limits::max(),std::numeric_limits::max()); + auto max_bound = GridPoint3D(std::numeric_limits::min(),std::numeric_limits::min(),std::numeric_limits::min()); + for(auto const& constraint_pt : _constraint_v) { + if(min_bound.x > constraint_pt.x) min_bound.x = constraint_pt.x; + if(min_bound.y > constraint_pt.y) min_bound.y = constraint_pt.y; + if(min_bound.z > constraint_pt.z) min_bound.z = constraint_pt.z; + if(max_bound.x < constraint_pt.x) max_bound.x = constraint_pt.x; + if(max_bound.y < constraint_pt.y) max_bound.y = constraint_pt.y; + if(max_bound.z < constraint_pt.z) max_bound.z = constraint_pt.z; + } + if( (max_bound.x - min_bound.x) >= (_width.x + padding.x) || + (max_bound.y - min_bound.y) >= (_width.y + padding.y) || + (max_bound.z - min_bound.z) >= (_width.z + padding.z) ) { + WIRERANGE3D_CRITICAL() << "Padding (" << x << "," << y << "," << z << ") cannot hold all constraints!" << std::endl; + throw std::exception(); + } + _padding = padding; + this->RederiveBounds(); + } + + void WireRange3D::SetMin(double x, double y, double z) { + auto pt = this->GridPoint3D(x,y,z); + for(auto const& constraint_pt : _constraint_v) { + if(constraint_pt.x < pt.x || + constraint_pt.y < pt.y || + constraint_pt.z < pt.z ) { + WIRERANGE3D_CRITICAL() << "Minimum bound @ (" << x << "," << y << "," << z << ") cannot hold registered constraint!" << std::endl; + throw std::exception(); + } + } + _min_fiducial = pt; + } + + void WireRange3D::SetMax(double x, double y, double z) { + auto pt = this->GridPoint3D(x,y,z); + for(auto const& constraint_pt : _constraint_v) { + if(constraint_pt.x > pt.x || + constraint_pt.y > pt.y || + constraint_pt.z > pt.z ) { + WIRERANGE3D_CRITICAL() << "Maximum bound @ (" << x << "," << y << "," << z << ") cannot hold registered constraint!" << std::endl; + throw std::exception(); + } + } + _max_fiducial = pt; + this->RederiveBounds(); + } + + void WireRange3D::AddConstraint(double x, double y, double z) { + if(!Valid()) { + WIRERANGE3D_CRITICAL() << "Cannot add constraint before configuration..." << std::endl; + throw std::exception(); + } + auto pt = this->GridPoint3D(x,y,z); + if(pt.x < _min_fiducial.x || pt.x > _max_fiducial.x || + pt.y < _min_fiducial.y || pt.y > _max_fiducial.y || + pt.z < _min_fiducial.z || pt.z > _max_fiducial.z) { + WIRERANGE3D_CRITICAL() << "Constraint @ (" << x << "," << y << "," << z << ") violates the bound!" << std::endl; + throw std::exception(); + } + auto min_bound = pt; + auto max_bound = pt; + for(auto const& constraint_pt : _constraint_v) { + if(min_bound.x > constraint_pt.x) min_bound.x = constraint_pt.x; + if(min_bound.y > constraint_pt.y) min_bound.y = constraint_pt.y; + if(min_bound.z > constraint_pt.z) min_bound.z = constraint_pt.z; + if(max_bound.x < constraint_pt.x) max_bound.x = constraint_pt.x; + if(max_bound.y < constraint_pt.y) max_bound.y = constraint_pt.y; + if(max_bound.z < constraint_pt.z) max_bound.z = constraint_pt.z; + } + if( (max_bound.x - min_bound.x) >= _width.x || + (max_bound.y - min_bound.y) >= _width.y || + (max_bound.z - min_bound.z) >= _width.z ) { + WIRERANGE3D_ERROR() << "Constraint @ (" << x << "," << y << "," << z << ")" + << " violates the width (" << _width.x << "," << _width.y << "," << _width.z << ")" << std::endl; + return; + } + _constraint_v.emplace_back(pt); + this->RederiveBounds(); + } + + void WireRange3D::SetWidth(double x, double y, double z) { + auto width = this->GridPoint3D(x,y,z); + if(_constraint_v.empty()) { + _width = width; + return; + } + // Check if this width is compatible with registered constraints + auto min_bound = GridPoint3D(std::numeric_limits::max(),std::numeric_limits::max(),std::numeric_limits::max()); + auto max_bound = GridPoint3D(std::numeric_limits::min(),std::numeric_limits::min(),std::numeric_limits::min()); + for(auto const& constraint_pt : _constraint_v) { + if(min_bound.x > constraint_pt.x) min_bound.x = constraint_pt.x; + if(min_bound.y > constraint_pt.y) min_bound.y = constraint_pt.y; + if(min_bound.z > constraint_pt.z) min_bound.z = constraint_pt.z; + if(max_bound.x < constraint_pt.x) max_bound.x = constraint_pt.x; + if(max_bound.y < constraint_pt.y) max_bound.y = constraint_pt.y; + if(max_bound.z < constraint_pt.z) max_bound.z = constraint_pt.z; + } + if( (max_bound.x - min_bound.x) >= (width.x + _padding.x) || + (max_bound.y - min_bound.y) >= (width.y + _padding.y) || + (max_bound.z - min_bound.z) >= (width.z + _padding.z) ) { + WIRERANGE3D_CRITICAL() << "Width (" << x << "," << y << "," << z << ") cannot hold all constraints!" << std::endl; + throw std::exception(); + } + _width = width; + this->RederiveBounds(); + } + + void WireRange3D::DeriveRange(const std::vector& points, + supera::GridPoint3D& min_pt, + supera::GridPoint3D& max_pt) const { + + if(!this->Valid()) { + WIRERANGE3D_CRITICAL() << "Configuration incomplete!" << std::endl; + throw std::exception(); + } + + static std::random_device rd; + static std::mt19937 mt(rd()); + + auto const min_bound = _min_bound; + auto const max_bound = _max_bound; + + // + // Local algorithm parameters + // (note min_pt, max_pt are merely a container, not diagonal edge of containing cube!) + // + static const int MIN_DEFAULT = std::numeric_limits::max(); + static const int MAX_DEFAULT = std::numeric_limits::min(); + min_pt.x = min_pt.y = min_pt.z = MIN_DEFAULT; + max_pt.x = max_pt.y = max_pt.z = MAX_DEFAULT; + + // + // Determine x boundary + // + for(auto const& pt : points) { + + if( pt.x < min_bound.x || pt.x > max_bound.x ) { + WIRERANGE3D_DEBUG() << "Ignoring point Grid X = " << pt.x + << " as it is outside the bound: " << min_bound.x + << " => " << max_bound.x << std::endl; + continue; + } + WIRERANGE3D_DEBUG() << "Accepting point Grid X = " << pt.x << std::endl; + + if(pt.x < min_pt.x) min_pt.x = pt.x; + if(pt.x > max_pt.x) max_pt.x = pt.x; + } + if(min_pt.x == MIN_DEFAULT || max_pt.x == MAX_DEFAULT) { + WIRERANGE3D_INFO() << "No point found to fit within X constraint points! Generating random boundary within constraint..." << std::endl; + std::uniform_int_distribution min_gen(min_bound.x,max_bound.x - _width.x + 1); + min_pt.x = min_gen(mt); + max_pt.x = min_pt.x + _width.x - 1; + WIRERANGE3D_INFO() << "New result: " << min_pt.x << " => " << max_pt.x << std::endl; + }else{ + WIRERANGE3D_INFO() << "Generating X range..." << std::endl; + this->Randomize(min_pt.x, max_pt.x, min_bound.x, max_bound.x, _width.x, _padding.x); + } + WIRERANGE3D_INFO() << std::endl; + + // + // Determine z boundary + // + for(auto const& pt : points) { + + if( pt.x < min_pt.x || pt.x > max_pt.x) + continue; + if( pt.z < min_bound.z || pt.z > max_bound.z ) { + WIRERANGE3D_DEBUG() << "Ignoring point Grid Z = " << pt.z + << " as it is outside the bound: " << min_bound.z << " => " << max_bound.z << std::endl; + continue; + } + WIRERANGE3D_DEBUG() << "Accepting point Grid Z = " << pt.z << std::endl; + + if(pt.z < min_pt.z) min_pt.z = pt.z; + if(pt.z > max_pt.z) max_pt.z = pt.z; + } + if(min_pt.z == MIN_DEFAULT || max_pt.z == MAX_DEFAULT) { + WIRERANGE3D_INFO() << "No point found to fit within Z constraint points! Generating random boundary within constraint..." << std::endl; + std::uniform_int_distribution min_gen(min_bound.z,max_bound.z - _width.z + 1); + min_pt.z = min_gen(mt); + max_pt.z = min_pt.z + _width.z - 1; + WIRERANGE3D_INFO() << "New result: " << min_pt.z << " => " << max_pt.z << std::endl; + }else{ + WIRERANGE3D_INFO() << "Generating Z range..." << std::endl; + this->Randomize(min_pt.z, max_pt.z, min_bound.z, max_bound.z, _width.z, _padding.z); + } + WIRERANGE3D_INFO() << std::endl; + + // + // Determine y boundary + // + for(auto const& pt : points) { + + if( pt.x < min_pt.x || pt.x > max_pt.x) + continue; + if( pt.z < min_pt.z || pt.z > max_pt.z) + continue; + if( pt.y < min_bound.y || pt.y > max_bound.y ) { + WIRERANGE3D_DEBUG() << "Ignoring point Grid Y = " << pt.y + << " as it is outside the bound: " << min_bound.y << " => " << max_bound.y << std::endl; + continue; + } + WIRERANGE3D_DEBUG() << "Accepting point Grid Y = " << pt.y << std::endl; + + if(pt.y < min_pt.y) min_pt.y = pt.y; + if(pt.y > max_pt.y) max_pt.y = pt.y; + } + if(min_pt.y == MIN_DEFAULT || max_pt.y == MAX_DEFAULT) { + WIRERANGE3D_INFO() << "No point found to fit within Y constraint points! Generating random boundary within constraint..." << std::endl; + std::uniform_int_distribution min_gen(min_bound.y,max_bound.y - _width.y + 1); + min_pt.y = min_gen(mt); + max_pt.y = min_pt.y + _width.y - 1; + WIRERANGE3D_INFO() << "New result: " << min_pt.y << " => " << max_pt.y << std::endl; + }else{ + WIRERANGE3D_INFO() << "Generating Y range..." << std::endl; + this->Randomize(min_pt.y, max_pt.y, min_bound.y, max_bound.y, _width.y, _padding.z); + } + WIRERANGE3D_INFO() << std::endl; + } + + void WireRange3D::Randomize(int& min_val, int& max_val, + const int min_bound, const int max_bound, + const int width, const int padding) const + { + WIRERANGE3D_INFO() << "Value range: " << min_val << " => " << max_val + << " ... absolute bound: " << min_bound << " => " << max_bound + << " ... target width: " << width << std::endl; + static std::random_device rd; + static std::mt19937 mt(rd()); + int space = width - (max_val - min_val + 1); + int rand_bound_min = 0; + int rand_bound_max = 0; + if( space == 0 ) { + WIRERANGE3D_INFO() << "Range exactly same as the target width. Nothing to do..." << std::endl; + return; + } + + else if( space > 0 ) { + WIRERANGE3D_INFO() << "Data point range = " << (max_val - min_val + 1) + << " is smaller than target width = " << width << std::endl; + // Width found is smaller than limit. + // Randomize x-edge within the available space. + if( (min_val - min_bound) < (max_bound - max_val) ) { + rand_bound_min = std::max(-space, min_bound - min_val); + rand_bound_max = 0; + WIRERANGE3D_INFO() << "Closer to min bound. Generating uniform random: " + << rand_bound_min << " => " << rand_bound_max << std::endl; + std::uniform_int_distribution shift_gen( rand_bound_min, rand_bound_max ); + int shift = shift_gen(mt); + max_val = min_val + shift + width - 1; + min_val = min_val + shift; + WIRERANGE3D_INFO() << "Applying shift: " << shift << " ... result: " << min_val << " => " << max_val << std::endl; + }else{ + rand_bound_min = 0; + rand_bound_max = std::min( space, max_bound - max_val); + WIRERANGE3D_INFO() << "Closer to max bound. Generating uniform random: " + << rand_bound_min << " => " << rand_bound_max << std::endl; + std::uniform_int_distribution shift_gen( rand_bound_min, rand_bound_max ); + int shift = shift_gen(mt); + min_val = max_val + shift - width + 1; + max_val = max_val + shift; + WIRERANGE3D_INFO() << "Applying shift: " << shift << " ... result: " << min_val << " => " << max_val << std::endl; + } + + }else { + WIRERANGE3D_INFO() << "Data point range = " << (max_val - min_val + 1) + << " is larger than target width = " << width << std::endl; + // Width found is larger than limit. + // Randomize x-edge within the available space. + rand_bound_min = min_val; + rand_bound_max = max_val - width + 1; + WIRERANGE3D_INFO() << "Generating uniform random: " << rand_bound_min << " => " << rand_bound_max << std::endl; + std::uniform_int_distribution min_gen( rand_bound_min, rand_bound_max ); + min_val = min_gen(mt); + max_val = min_val + width - 1; + WIRERANGE3D_INFO() << "New result: " << min_val << " => " << max_val << std::endl; + } + } + +} + +#endif diff --git a/WireRange3D.h b/WireRange3D.h new file mode 100644 index 0000000..fde6b42 --- /dev/null +++ b/WireRange3D.h @@ -0,0 +1,159 @@ +/** + * \file WireRange3D.h + * + * \ingroup MeatSlicer + * + * \brief Class def header for a class WireRange3D + * + * @author kazuhiro + */ + +/** \addtogroup MeatSlicer + + @{*/ +#ifndef WIRERANGE3D_H +#define WIRERANGE3D_H + +#include +#include +#include +#include +#include + +namespace supera { + + class GridPoint3D { + public: + GridPoint3D(int xval = std::numeric_limits::max(), + int yval = std::numeric_limits::max(), + int zval = std::numeric_limits::max()) + : x(xval) + , y(yval) + , z(zval) + {} + ~GridPoint3D(){} + + GridPoint3D(const GridPoint3D& rhs) + : x(rhs.x) + , y(rhs.y) + , z(rhs.z) + {} + + inline bool operator < (const GridPoint3D& pt) const { + if( x < pt.x ) return true; + if( x > pt.x ) return false; + if( y < pt.y ) return true; + if( y > pt.y ) return false; + if( z < pt.z ) return true; + if( z > pt.z ) return false; + return false; + } + inline bool operator == (const GridPoint3D& pt) const + { return ( x == pt.x && y == pt.y && z == pt.z ); } + inline bool operator != (const GridPoint3D& pt) const + { return !( (*this) == pt ); } + + inline bool operator > (const GridPoint3D& pt) const + { + if( (*this) == pt ) return false; + return !( (*this) < pt); + } + + inline bool Valid() const + { + return (x != std::numeric_limits::max() && + y != std::numeric_limits::max() && + z != std::numeric_limits::max()); + } + + int x, y, z; + }; + + /** + \class WireRange3D + User defined class WireRange3D ... these comments are used to generate + doxygen documentation! + */ + class WireRange3D{ + + public: + + /// Default constructor + WireRange3D() + : _verbosity(2) + , _width() + , _min_bound() + , _max_bound() + , _min_fiducial() + , _max_fiducial() + , _padding(0,0,0) + , _grid_size_x(0) + , _grid_size_y(0) + , _grid_size_z(0) + {} + + /// Default destructor + ~WireRange3D(){} + + inline void Clear() { _constraint_v.clear(); } + + void AddConstraint(double x, double y, double z); + + void SetWidth(double x, double y, double z); + + void SetMin(double x, double y, double z); + + void SetMax(double x, double y, double z); + + void SetPadding(double x, double y, double z); + + inline void Verbosity(unsigned int v=2) { _verbosity = v; } + + inline void SetGridSize(double x, double y, double z) + { _grid_size_x = x; _grid_size_y = y; _grid_size_z = z; } + + inline const std::vector GetConstraints() const + { return _constraint_v; } + + supera::GridPoint3D GridPoint3D(double x, double y, double z) const; + inline double GridSizeX() const { return _grid_size_x; } + inline double GridSizeY() const { return _grid_size_y; } + inline double GridSizeZ() const { return _grid_size_z; } + + bool Valid() const; + + void DeriveRange(const std::vector& points, + supera::GridPoint3D& min_pt, + supera::GridPoint3D& max_pt) const; + + inline const supera::GridPoint3D& EffectiveMin() const + { return _min_bound; } + + inline const supera::GridPoint3D& EffectiveMax() const + { return _max_bound; } + + inline unsigned int Verbosity() const { return _verbosity; } + + std::string PrintConfig() const; + + private: + unsigned int _verbosity; + supera::GridPoint3D _width; + supera::GridPoint3D _min_bound, _max_bound; + supera::GridPoint3D _min_fiducial, _max_fiducial; + supera::GridPoint3D _padding; + double _grid_size_x, _grid_size_y, _grid_size_z; + std::vector _constraint_v; /// A list of 3D grid point that must be included + + void RederiveBounds(); + void Randomize(int& min_val, int& max_val, + const int min_bound, const int max_bound, + const int width, const int padding) const; + + }; + +} + +#endif +/** @} */ // end of doxygen group + diff --git a/arxiv/MCOriginTree.cxx b/arxiv/MCOriginTree.cxx new file mode 100644 index 0000000..d85340b --- /dev/null +++ b/arxiv/MCOriginTree.cxx @@ -0,0 +1,511 @@ +#ifndef MCPARTICLETREE_CXX +#define MCPARTICLETREE_CXX + +#include "MCParticleTree.h" +#include + +namespace supera { + + std::string MCNode::dump() const + { + std::stringstream ss; + ss << "Source " << (int)(source_type) << " Origin: " << origin << " PDG " << pdg << " TrackID " << track_id << std::endl; + return ss.str(); + } + + bool MCRoot::is_daughter(const size_t& parent_id) const + { + if(track_id == parent_id) return true; + for(auto const& daughter : daughter_v) + if(daughter.track_id == parent_id) return true; + return false; + } + + bool MCRoot::is_daughter(const larcv::Vertex& daughter_start) const + { + if(start == daughter_start || end == daughter_start) return true; + for(auto const& daughter : daughter_v) + if(daughter.start == daughter_start || daughter.end == daughter_start) return true; + return false; + } + + double MCRoot::dt(const MCNode& node) const + { + double min_dt = -1; + double dt=0; + + dt = node.start.T() - start.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + dt = node.start.T() - end.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + + for(auto const& daughter : daughter_v) { + dt = node.start.T() - daughter.start.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + dt = node.start.T() - daughter.end.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + } + return min_dt; + } + + void MCParticleTree::dump() const + { + auto const& primary_v = PrimaryArray(); + for(size_t idx=0; idx (" + << primary.end.X() << "," << primary.end.Y() << "," << primary.end.Z() << ")" + << std::endl; + return primary_idx; + } + } + return larcv::kINVALID_SIZE; + } + + size_t MCParticleTree::FindPrimary(const size_t parent_id, + const size_t ancestor_id) const + { + if(parent_id != larcv::kINVALID_SIZE) { + for(size_t primary_idx=0; primary_idx<_primary_v.size(); ++primary_idx) { + auto const& primary = _primary_v[primary_idx]; + if(primary.is_daughter(parent_id)) { + LARCV_DEBUG() << "Primary found via parent id " << parent_id << std::endl; + return primary_idx; + } + } + } + if(ancestor_id != larcv::kINVALID_SIZE) { + for(size_t primary_idx=0; primary_idx<_primary_v.size(); ++primary_idx) { + auto const& primary = _primary_v[primary_idx]; + if(primary.is_daughter(ancestor_id)) { + LARCV_DEBUG() << "Primary found via ancestor id " << ancestor_id << std::endl; + return primary_idx; + } + } + } + return larcv::kINVALID_SIZE; + } + + void MCParticleTree::Register(const std::vector& mctruth_v, + const std::vector& mctrack_v, + const std::vector& mcshower_v) + { + size_t old_size = _primary_v.size(); + _primary_v.clear(); + _primary_v.reserve(old_size); + if(_used_mctrack_v.size() <= mctrack_v.size()) + _used_mctrack_v.resize(mctrack_v.size()); + if(_used_mcshower_v.size() <= mcshower_v.size()) + _used_mcshower_v.resize(mcshower_v.size()); + + for(auto& used : _used_mctrack_v ) used = 0; + for(auto& used : _used_mcshower_v) used = 0; + + // + // Register primaries + // + if(!_use_g4_primary) { + for (size_t mctruth_index = 0; mctruth_index < mctruth_v.size(); ++mctruth_index) { + + auto const& mctruth = mctruth_v[mctruth_index]; + + if(_origin_filter && mctruth.Origin() != _origin_filter) + continue; + + if(mctruth.Origin() == 1) // neutrino + DefineNeutrinoPrimary(mctruth_v); + } + DefinePrimary(mctruth_v); + }else + DefinePrimary(mctrack_v,mcshower_v); + + // + // Register secondaries + // + DefineSecondary(mctrack_v,mcshower_v); + EstimateSecondary(mctrack_v,mcshower_v); + + // + // Report + // + if(logger().level() <= larcv::msg::kINFO) { + std::stringstream ss; + for(size_t primary_idx=0; primary_idx<_primary_v.size(); ++primary_idx) { + + auto const& primary = _primary_v[primary_idx]; + + ss << " Primary " << primary_idx << " Source " << (int)(primary.source_type) << " @ " << primary.source_index + << " ... PDG " << primary.pdg << " TrackID " << primary.track_id + << " with " << primary.daughter_v.size() << " children" + << std::endl; + + for(size_t child_idx=0; child_idx& mctruth_v) + { + // + // In case of neutrino generator, we set neutrino as primary + // + for (size_t mctruth_idx=0; mctruth_idx& mctruth_v) + { + // + // In case of neutrino generator, we set neutrino as primary + // + for (size_t mctruth_idx=0; mctruth_idx& mctrack_v, + const std::vector& mcshower_v) + { + for(size_t track_idx=0; track_idx& mctrack_v, + const std::vector& mcshower_v) + { + size_t used_count_mcshower = 0; + size_t used_count_mctrack = 0; + for(auto const& v : _used_mctrack_v ) if(v) ++used_count_mctrack; + for(auto const& v : _used_mcshower_v) if(v) ++used_count_mcshower; + size_t last_used_count_mctrack = larcv::kINVALID_SIZE; + size_t last_used_count_mcshower = larcv::kINVALID_SIZE; + + while(used_count_mcshower != last_used_count_mcshower || + used_count_mctrack != last_used_count_mctrack) { + + // Update "last" counter + last_used_count_mctrack = used_count_mctrack; + last_used_count_mcshower = used_count_mcshower; + + // Scan tracks for exact parentage connection + for(size_t track_idx=0; track_idx& mctrack_v, + const std::vector& mcshower_v) + { + if(_dt_max <=0) return; + + double primary_min_time = 1.e20; + double primary_max_time = 0.; + for(auto const& primary : _primary_v) { + if(primary.start.T() < primary_min_time) primary_min_time = primary.start.T(); + if(primary.end.T() > primary_max_time) primary_max_time = primary.end.T(); + } + + for(size_t track_idx=0; track_idx " << primary_max_time << ")" + << std::endl; + continue; + } + size_t primary_idx = larcv::kINVALID_SIZE; + double min_dt = 1e20; + for(size_t idx=0; idx<_primary_v.size(); ++idx) { + auto const& primary = _primary_v[idx]; + auto const dt = primary.dt(node); + if(dt<0) continue; + if(dt < min_dt) { + min_dt = dt; + primary_idx = idx; + } + } + if(min_dt > _dt_max) continue; + LARCV_INFO() << "Associating (time-approx) MCTrack (index " << track_idx + << " PDG " << track.PdgCode() << " Origin " << track.Origin() + << ") with primary (index " << primary_idx + << " PDG " << _primary_v[primary_idx].part.PdgCode() + << " Origin " << _primary_v[primary_idx].origin + << ")" << std::endl; + _primary_v[primary_idx].daughter_v.emplace_back(std::move(node)); + _used_mctrack_v[track_idx] = 1; + } + + for(size_t shower_idx=0; shower_idx " << primary_max_time << ")" + << std::endl; + continue; + } + size_t primary_idx = larcv::kINVALID_SIZE; + double min_dt = 1e20; + for(size_t idx=0; idx<_primary_v.size(); ++idx) { + auto const& primary = _primary_v[idx]; + auto const dt = primary.dt(node); + if(dt<0) continue; + if(dt < min_dt) { + min_dt = dt; + primary_idx = idx; + } + } + LARCV_INFO() << "Associating (time-approx) MCShower (index " << shower_idx + << " PDG " << shower.PdgCode() << " Origin " << shower.Origin() + << ") with primary (index " << primary_idx + << " PDG " << _primary_v[primary_idx].part.PdgCode() + << " Origin " << _primary_v[primary_idx].origin + << ")" << std::endl; + if(min_dt > _dt_max) continue; + _primary_v[primary_idx].daughter_v.emplace_back(std::move(node)); + _used_mcshower_v[shower_idx] = 1; + } + } + +} + +#endif diff --git a/arxiv/MCOriginTree.h b/arxiv/MCOriginTree.h new file mode 100644 index 0000000..278667f --- /dev/null +++ b/arxiv/MCOriginTree.h @@ -0,0 +1,154 @@ +/** + * \file MCParticleTree.h + * + * \ingroup MeatSlicer + * + * \brief Class def header for a class MCParticleTree + * + * @author kazuhiro + */ + +/** \addtogroup MeatSlicer + + @{*/ +#ifndef MCPARTICLETREE_H +#define MCPARTICLETREE_H + +#include +#include "larcv/core/DataFormat/Vertex.h" +#include "larcv/core/DataFormat/Particle.h" +#include "FMWKInterface.h" +#include "larcv/core/Base/larcv_base.h" +namespace supera { + + class MCNode { + public: + enum class SourceType_t { + kMCTruth, + kMCTrack, + kMCShower, + kUnknown + }; + + public: + MCNode() : origin(0) + , pdg(0) + , track_id(larcv::kINVALID_SIZE) + , start() + , end() + , source_index(larcv::kINVALID_SIZE) + , source_type(SourceType_t::kUnknown) + {} + ~MCNode(){} + + unsigned short origin; + int pdg; + size_t track_id; + larcv::Vertex start; + larcv::Vertex end; + size_t source_index; + SourceType_t source_type; + + std::string dump() const; + }; + + class MCRoot : public MCNode{ + public: + MCRoot() : MCNode() + , daughter_v() + {} + MCRoot(const MCNode& node) : MCNode(node) + , daughter_v() + {} + ~MCRoot(){} + /// Check if supplied parent track id belongs to this tree + bool is_daughter(const size_t& parent_id) const; + /** + Check if supplied node belongs to this Root via 0) start-start, 1) end-start matching + */ + bool is_daughter(const larcv::Vertex& start) const; + /** + Compute the smallest positive dT among any particle in this tree and the provided node + */ + double dt(const MCNode& node) const; + + std::vector daughter_v; + ::larcv::Particle part; + + }; + + /** + \class MCParticleTree + User defined class MCParticleTree ... these comments are used to generate + doxygen documentation! + */ + class MCParticleTree : public larcv::larcv_base { + + public: + + /// Default constructor + MCParticleTree() : larcv::larcv_base("MCParticleTree") + , _origin_filter(0) + {} + + /// Default destructor + ~MCParticleTree(){} + + void configure(const Config_t& cfg) + { + set_verbosity((::larcv::msg::Level_t)(cfg.get("Verbosity",logger().level()))); + _use_g4_primary = cfg.get("UseG4Primary"); + _dt_max = cfg.get("DTMax"); + } + + void Register(const std::vector& mctruth_v, + const std::vector& mctrack_v, + const std::vector& mcshower_v); + + void FilterOrigin(unsigned short flag) + { _origin_filter = flag; } + + const std::vector& PrimaryArray() const + { return _primary_v; } + + void dump() const; + + private: + + std::vector _primary_v; + std::vector _used_mctrack_v; + std::vector _used_mcshower_v; + + unsigned short _origin_filter; + double _dt_max; + bool _use_g4_primary; + + MCNode FillNode(const supera::LArMCTrack_t& mct); + + MCNode FillNode(const supera::LArMCShower_t& mcs); + + size_t FindPrimary(const larcv::Vertex& start, + const size_t parent_id, + const size_t ancestor_id) const; + + size_t FindPrimary(const size_t parent_id, + const size_t ancestor_id) const; + + void DefineNeutrinoPrimary(const std::vector& mctruth_v); + + void DefinePrimary(const std::vector& mctruth_v); + + void DefinePrimary(const std::vector& mctrack_v, + const std::vector& mcshower_v); + + void DefineSecondary(const std::vector& mctrack_v, + const std::vector& mcshower_v); + + void EstimateSecondary(const std::vector& mctrack_v, + const std::vector& mcshower_v); + + }; +} +#endif +/** @} */ // end of doxygen group + diff --git a/arxiv/MCParticleHelper.cxx b/arxiv/MCParticleHelper.cxx new file mode 100644 index 0000000..5181fb6 --- /dev/null +++ b/arxiv/MCParticleHelper.cxx @@ -0,0 +1,455 @@ +#ifndef __SUPERA_MCROIMAKER_CXX__ +#define __SUPERA_MCROIMAKER_CXX__ + +#include "MCParticleHelper.h" +#include "larcv/core/Base/larbys.h" +#include "FMWKInterface.h" +#include // ROOT +#include +namespace supera { + + void MCParticleHelper::configure(const supera::Config_t& cfg) + { + LARCV_DEBUG() << "start" << std::endl; + set_verbosity((::larcv::msg::Level_t)(cfg.get("Verbosity",logger().level()))); + _max_time_tick = cfg.get("MaxTimeTick"); + _time_padding = cfg.get("TimePadding"); + _wire_padding = cfg.get("WirePadding"); + _apply_sce = cfg.get("ApplySCE"); + + LARCV_NORMAL() << "Configuration called..." << std::endl + << " Padding (wire,time) = (" << _wire_padding << "," << _time_padding << ")" << std::endl; + } + + WTRangeArray_t MCParticleHelper::WireTimeBoundary(const LArMCTrack_t& mct, + const std::vector& sch_v) const + { + LARCV_DEBUG() << "start" << std::endl; + // result is N planes' wire boundary + time boundary (N+1 elements) + WTRangeArray_t result(supera::Nplanes() + 1); + + for (auto const& sch : sch_v) { + + auto const wire = ChannelToWireID(sch.Channel()); + auto& wrange = result[wire.Plane]; + auto& trange = result.back(); + + for (auto const& tdc_ide_v : sch.TDCIDEMap()) { + bool store = false; + double tick = TPCTDC2Tick((double)(tdc_ide_v.first)); + //if(tick<0 || tick >= NumberTimeSamples()) continue; + if (tick < 0 || tick >= _max_time_tick) continue; + tick += 0.5; + for (auto const& ide : tdc_ide_v.second) { + unsigned int trackid = (ide.trackID < 0 ? (-1 * ide.trackID) : ide.trackID); + if (trackid != mct.TrackID()) continue; + + store = true; + LARCV_DEBUG() << "IDE wire = " << (unsigned int)wire.Wire + << " ... tick = " << (unsigned int)tick << std::endl + << " (tdc=" << tdc_ide_v.first << ", x=" << ide.x << ")" << std::endl; + break; + } + if (!store) continue; + if (!wrange.valid()) wrange.Set((unsigned int)wire.Wire, (unsigned int)(wire.Wire)); + else wrange += (unsigned int)(wire.Wire); + if (!trange.valid()) trange.Set((unsigned int)(tick), (unsigned int)(tick)); + else trange += (unsigned int)(tick); + } + } + + for (auto& r : result) if (!r.valid()) r.Set(0, 0); + + for (size_t plane = 0; plane <= supera::Nplanes(); ++plane) + + LARCV_INFO() << "Single MCShower ... Plane " << plane + << " bound " << result[plane].Start() << " => " << result[plane].End() << std::endl; + + return result; + } + + WTRangeArray_t MCParticleHelper::WireTimeBoundary(const LArMCTrack_t& mct) const + { + LARCV_DEBUG() << "start" << std::endl; + const double drift_velocity = ::supera::DriftVelocity() * 1.0e-3; // make it cm/ns + //const int tick_max = ::supera::NumberTimeSamples(); + const double plane_tick_offset = PlaneTickOffset(0,1); // plane 1 as a reference + const int tick_max = _max_time_tick; + TVector3 xyz; xyz[0] = xyz[1] = xyz[2] = 0.; + + // result is N planes' wire boundary + time boundary (N+1 elements) + WTRangeArray_t result(::supera::Nplanes() + 1); + + for (auto& step : mct) { + + xyz[0] = step.X(); + xyz[1] = step.Y(); + xyz[2] = step.Z(); + if(_apply_sce) ApplySCE(xyz); + + // Figure out time + int tick = (int)(::supera::TPCG4Time2Tick(step.T() + (xyz[0] / drift_velocity)) + plane_tick_offset + 0.5); + + if (tick < 0 || tick >= tick_max) { + LARCV_DEBUG() << "tick out of time: " << tick << std::endl; + continue; + } + + auto& trange = result.back(); + if (!trange.valid()) trange.Set((unsigned int)tick, (unsigned int)tick); // 1st time: "set" it + else trange += (unsigned int)tick; // >1st time: "add (include)" it + + // Figure out wire per plane + LARCV_DEBUG() << "(x,t,v) = (" << xyz[0] << "," << step.T() << "," << drift_velocity << ") ... tick = " << tick << std::endl; + for (size_t plane = 0; plane < supera::Nplanes(); ++plane) { + + auto wire_id = ::supera::NearestWire(xyz, plane); + auto& wrange = result[plane]; + LARCV_DEBUG() << "(y,z) = (" << xyz[1] << "," << xyz[2] << ") ... @ plane " << plane << " wire = " << wire_id + << (wrange.valid() ? " updating wire-range" : " setting wire-range") << std::endl; + if (!wrange.valid()) wrange.Set((unsigned int)wire_id, (unsigned int)wire_id); + else wrange += (unsigned int)wire_id; + + } + } + + for (auto& r : result) if (!r.valid()) r.Set(0, 0); + //if(!r.valid() || (r.End() - r.Start()) < 2) r.Set(0,0); + + for (size_t plane = 0; plane <= supera::Nplanes(); ++plane) + + LARCV_INFO() << "Single MCTrack ... Plane " << plane + << " bound " << result[plane].Start() << " => " << result[plane].End() << std::endl; + + return result; + } + + WTRangeArray_t MCParticleHelper::WireTimeBoundary(const LArMCShower_t& mcs) const + { + LARCV_DEBUG() << "start" << std::endl; + const double drift_velocity = ::supera::DriftVelocity() * 1.0e-3; // make it cm/ns + //const int tick_max = ::supera::NumberTimeSamples(); + const int tick_max = _max_time_tick; + double xyz[3] = {0.}; + + // result is N planes' wire boundary + time boundary (N+1 elements) + WTRangeArray_t result(::supera::Nplanes() + 1); + + auto const& detprofile = mcs.DetProfile(); + double energy = detprofile.E(); + + double showerlength = 13.8874 + 0.121734 * energy - (3.75571e-05) * energy * energy; + showerlength *= 2.5; + //double showerlength = 100.0; + double detprofnorm = sqrt( detprofile.Px() * detprofile.Px() + detprofile.Py() * detprofile.Py() + detprofile.Pz() * detprofile.Pz() ); + TLorentzVector showerend; + const double plane_tick_offset = PlaneTickOffset(0,1); // plane 1 as a reference + showerend[0] = detprofile.X() + showerlength * (detprofile.Px() / detprofnorm); + showerend[1] = detprofile.Y() + showerlength * (detprofile.Py() / detprofnorm); + showerend[2] = detprofile.Z() + showerlength * (detprofile.Pz() / detprofnorm); + showerend[3] = detprofile.T(); + //std::cout << "showerlength: " << showerlength << " norm=" << detprofnorm << std::endl; + + std::vector< TLorentzVector > step_v; + step_v.push_back( detprofile.Position() ); + step_v.push_back( showerend ); + + for (auto& step : step_v) { + xyz[0] = step.X(); + xyz[1] = step.Y(); + xyz[2] = step.Z(); + if(_apply_sce) ApplySCE(xyz); + + // Figure out time + int tick = (int)(::supera::TPCG4Time2Tick(step.T() + (xyz[0] / drift_velocity)) + plane_tick_offset + 0.5); + + if (tick < 0 || tick >= tick_max) continue; + + auto& trange = result.back(); + if (!trange.valid()) trange.Set((unsigned int)tick, (unsigned int)tick); + else trange += (unsigned int)tick; + + // Figure out wire per plane + for (size_t plane = 0; plane < supera::Nplanes(); ++plane) { + + auto wire_id = ::supera::NearestWire(xyz, plane); + + auto& wrange = result[plane]; + if (!wrange.valid()) wrange.Set((unsigned int)wire_id, (unsigned int)wire_id); + else wrange += (unsigned int)wire_id; + } + + LARCV_DEBUG() << "(x,t,v) = (" << xyz[0] << "," << step.T() << "," << drift_velocity << ") ... tick = " << tick << std::endl; + } + + for (auto& r : result) if (!r.valid()) r.Set(0, 0); + + for (size_t plane = 0; plane <= supera::Nplanes(); ++plane) + + LARCV_INFO() << "Single MCShower ... Plane " << plane + << " bound " << result[plane].Start() << " => " << result[plane].End() << std::endl; + + return result; + } + + WTRangeArray_t MCParticleHelper::WireTimeBoundary(const LArMCShower_t& mcs, const std::vector& sch_v) const + { + LARCV_DEBUG() << "start" << std::endl; + // result is N planes' wire boundary + time boundary (N+1 elements) + WTRangeArray_t result(::supera::Nplanes() + 1); + + std::set daughters; + for (auto const& trackid : mcs.DaughterTrackID()) daughters.insert(trackid); + daughters.insert(mcs.TrackID()); + + for (auto const& sch : sch_v) { + + auto const wire = ChannelToWireID(sch.Channel()); + auto& wrange = result[wire.Plane]; + auto& trange = result.back(); + + for (auto const& tdc_ide_v : sch.TDCIDEMap()) { + bool store = false; + double tick = TPCTDC2Tick((double)(tdc_ide_v.first)); + //if(tick<0 || tick >= NumberTimeSamples()) continue; + if (tick < 0 || tick >= _max_time_tick) continue; + tick += 0.5; + for (auto const& ide : tdc_ide_v.second) { + unsigned int trackid = (ide.trackID < 0 ? (-1 * ide.trackID) : ide.trackID); + if (daughters.find(trackid) != daughters.end()) { + store = true; + LARCV_DEBUG() << "IDE wire = " << (unsigned int)wire.Wire + << " ... tick = " << (unsigned int)tick << std::endl + << " (tdc=" << tdc_ide_v.first << ", x=" << ide.x << ")" << std::endl; + break; + } + } + if (!store) continue; + if (!wrange.valid()) wrange.Set((unsigned int)wire.Wire, (unsigned int)(wire.Wire)); + else wrange += (unsigned int)(wire.Wire); + if (!trange.valid()) trange.Set((unsigned int)(tick), (unsigned int)(tick)); + else trange += (unsigned int)(tick); + } + } + + for (auto& r : result) if (!r.valid()) r.Set(0, 0); + + for (size_t plane = 0; plane <= supera::Nplanes(); ++plane) + + LARCV_INFO() << "Single MCShower ... Plane " << plane + << " bound " << result[plane].Start() << " => " << result[plane].End() << std::endl; + + return result; + } + + std::vector MCParticleHelper::WTRange2BB(const WTRangeArray_t& wtrange_v) const + { + LARCV_DEBUG() << "start" << std::endl; + std::vector bb_v; + if (wtrange_v.empty()) return bb_v; + + bb_v.reserve(wtrange_v.size() - 1); + for (size_t i = 0; i < wtrange_v.size() - 1; ++i) { + auto const& wrange = wtrange_v[i]; + auto const& trange = wtrange_v.back(); + + if(!wrange.valid() || !trange.valid()) { + LARCV_INFO() << "Invalid WTRange_t for Plane " << i << std::endl + << " W: " << wrange.Start() << " => " << wrange.End() << (wrange.valid() ? " good" : " bad") + << " ... T: " << trange.Start() << " => " << trange.End() << (trange.valid() ? " good" : " bad") << std::endl; + bb_v.push_back(larcv::BBox2D()); + continue; + } + + double width, height; + double origin_x, origin_y; + width = (int)(wrange.End()) - (int)(wrange.Start()); + height = (int)(trange.End()) - (int)(trange.Start()); + + origin_x = wrange.Start(); + origin_y = trange.Start(); + + //if(wrange.valid() && (wrange.End() - wrange.Start())) { + if (wrange.valid() && wrange.Start()) { + width = (int)(wrange.End()) - (int)(wrange.Start()) + 1 + 2 * ((int)_wire_padding); + origin_x = (int)(wrange.Start()) - (int)(_wire_padding); + } + //if(trange.valid() && (trange.End() - trange.Start())) { + if (trange.valid() && trange.Start()) { + height = (int)(trange.End()) - (int)(trange.Start()) + 1 + 2 * (int)(_time_padding); + origin_y = (int)(trange.Start()) - (int)(_time_padding); + } + + LARCV_INFO() << "Constructing BBox2D from WTRange_t for Plane " << i + << " w/ padding (w,t) = (" << _wire_padding << "," << _time_padding << ")" << std::endl + << " W: " << wrange.Start() << " => " << wrange.End() << (wrange.valid() ? " good" : " bad") + << " ... T: " << trange.Start() << " => " << trange.End() << (trange.valid() ? " good" : " bad") << std::endl + << " Origin: (" << origin_x << "," << origin_y << ")" << std::endl + << " Height = " << height << " Width = " << width << std::endl; + bb_v.emplace_back(origin_x,origin_y,origin_x+width,origin_y+height); + } + return bb_v; + } + + std::vector MCParticleHelper::MakeBBox2D( const supera::LArMCTrack_t& mct, const int time_offset) const + { + LARCV_DEBUG() << "start" << std::endl; + auto wtrange_v = WireTimeBoundary(mct); + // Add time offset + wtrange_v.back().Set(wtrange_v.back().Start()+time_offset, wtrange_v.back().End()+time_offset); + return WTRange2BB(wtrange_v); + } + + std::vector MCParticleHelper::MakeBBox2D( const supera::LArMCTrack_t& mct, const std::vector& sch_v, const int time_offset) const + { + LARCV_DEBUG() << "start" << std::endl; + auto wtrange_v = WireTimeBoundary(mct, sch_v); + wtrange_v.back().Set(wtrange_v.back().Start()+time_offset, wtrange_v.back().End()+time_offset); + return WTRange2BB(wtrange_v); + } + + std::vector MCParticleHelper::MakeBBox2D( const supera::LArMCShower_t& mcs, const int time_offset) const + { + LARCV_DEBUG() << "start" << std::endl; + auto wtrange_v = WireTimeBoundary(mcs); + // Add time offset + wtrange_v.back().Set(wtrange_v.back().Start()+time_offset, wtrange_v.back().End()+time_offset); + return WTRange2BB(wtrange_v); + } + + std::vector MCParticleHelper::MakeBBox2D( const supera::LArMCShower_t& mcs, const std::vector& sch_v, const int time_offset) const + { + LARCV_DEBUG() << "start" << std::endl; + auto wtrange_v = WireTimeBoundary(mcs, sch_v); + wtrange_v.back().Set(wtrange_v.back().Start()+time_offset, wtrange_v.back().End()+time_offset); + return WTRange2BB(wtrange_v); + } + + ::larcv::Particle MCParticleHelper::MakeParticle( const supera::LArMCTrack_t& mct) const + { + LARCV_DEBUG() << "start" << std::endl; + LARCV_INFO() << "Assessing MCTrack G4Track ID = " << mct.TrackID() << " PdgCode " << mct.PdgCode() << std::endl; + double xyz[3] = {0.}; + + ::larcv::Particle res; + res.Shape(::larcv::kShapeTrack); + //res.Type(::larcv::PdgCode2ROIType(mct.PdgCode())); + if (mct.size()) + res.EnergyDeposit(mct.front().E() - mct.back().E()); + else + res.EnergyDeposit(0); + res.EnergyInit(mct.Start().E()); + + xyz[0] = mct.Start().X(); + xyz[1] = mct.Start().Y(); + xyz[2] = mct.Start().Z(); + if(_apply_sce) ApplySCE(xyz); + res.Position(xyz[0], xyz[1], xyz[2], mct.Start().T()); + + xyz[0] = mct.End().X(); + xyz[1] = mct.End().Y(); + xyz[2] = mct.End().Z(); + if(_apply_sce) ApplySCE(xyz); + res.EndPosition(xyz[0], xyz[1], xyz[2], mct.End().T()); + + res.CreationProcess(mct.Process()); + + if(mct.size()>0) { + auto const& first_step = mct.front(); + xyz[0] = first_step.X(); + xyz[1] = first_step.Y(); + xyz[2] = first_step.Z(); + if(_apply_sce) ApplySCE(xyz); + res.FirstStep(xyz[0], xyz[1], xyz[2], first_step.T()); + } + if(mct.size()>1) { + auto const& last_step = mct.back(); + res.LastStep(last_step.X(), last_step.Y(), last_step.Z(), last_step.T()); + double length=0; + for(size_t step_idx=1; step_idx + +// LArSoft +//#include "MCBase/MCTrack.h" +//#include "MCBase/MCShower.h" +//#include "Simulation/SimChannel.h" +//#include "SimulationBase/MCParticle.h" + +// LArCV +#include "larcv/core/Base/larcv_base.h" +#include "larcv/core/DataFormat/Particle.h" +#include "larcv/core/DataFormat/BBox.h" +#include "FMWKInterface.h" +#include "Range.h" +namespace supera { + + typedef ::larcv::Range WTRange_t; + typedef std::vector WTRangeArray_t; + + class MCParticleHelper : public ::larcv::larcv_base { + + public: + + MCParticleHelper() : larcv::larcv_base("MCParticleHelper") + , _max_time_tick(9600) + , _time_padding(10) + , _wire_padding(10) + {} + + virtual ~MCParticleHelper() {} + + void configure(const supera::Config_t& cfg); + /** + Given single MCTrack, returns length 4 range array (3 planes + time) \n + which contains all trajectory points of input MCTrack. + */ + WTRangeArray_t WireTimeBoundary( const supera::LArMCTrack_t& mct ) const; + + WTRangeArray_t WireTimeBoundary( const supera::LArMCTrack_t& mct, + const std::vector& sch_v ) const; + + WTRangeArray_t WireTimeBoundary( const supera::LArMCShower_t& mcs ) const; + + WTRangeArray_t WireTimeBoundary( const supera::LArMCShower_t& mcs, + const std::vector& sch_v ) const; + + std::vector MakeBBox2D( const supera::LArMCTrack_t& mct, + const int time_offset ) const; + + std::vector MakeBBox2D( const supera::LArMCTrack_t& mct, + const std::vector& sch_v, + const int time_offset ) const; + + std::vector MakeBBox2D( const supera::LArMCShower_t& mcs, + const int time_offset ) const; + + std::vector MakeBBox2D( const supera::LArMCShower_t& mcs, + const std::vector& sch_v, + const int time_offset ) const; + + ::larcv::Particle MakeParticle( const supera::LArMCTrack_t& mct) const; + + ::larcv::Particle MakeParticle( const supera::LArMCShower_t& mcs) const; + + private: + + std::vector WTRange2BB(const WTRangeArray_t&) const; + + unsigned int _max_time_tick; ///< Maximum tick number in time + unsigned int _time_padding; ///< Padding in time axis (height) for MCParticleHelper::Format function + unsigned int _wire_padding; ///< Padding in wire axis (width) for MCParticleHelper::Format function + bool _apply_sce; + }; +} + +#endif +//#endif +//#endif diff --git a/arxiv/MCParticleTree.cxx b/arxiv/MCParticleTree.cxx new file mode 100644 index 0000000..2b731e1 --- /dev/null +++ b/arxiv/MCParticleTree.cxx @@ -0,0 +1,355 @@ +#ifndef MCPARTICLETREE_CXX +#define MCPARTICLETREE_CXX + +#include "MCParticleTree.h" +#include + +namespace supera { + + std::string MCNode::dump() const + { + std::stringstream ss; + ss << "Source " << (int)(source_type) << " Origin: " << origin << " PDG " << pdg << " TrackID " << track_id << std::endl; + return ss.str(); + } + + bool MCRoot::is_daughter(const size_t& parent_id) const + { + if(track_id == parent_id) return true; + for(auto const& daughter : daughter_v) + if(daughter.track_id == parent_id) return true; + return false; + } + + bool MCRoot::is_daughter(const larcv::Vertex& daughter_start) const + { + if(start == daughter_start || end == daughter_start) return true; + for(auto const& daughter : daughter_v) + if(daughter.start == daughter_start || daughter.end == daughter_start) return true; + return false; + } + + double MCRoot::dt(const MCNode& node) const + { + double min_dt = -1; + double dt=0; + + dt = node.start.T() - start.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + dt = node.start.T() - end.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + + for(auto const& daughter : daughter_v) { + dt = node.start.T() - daughter.start.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + dt = node.start.T() - daughter.end.T(); + if(dt>0 && (min_dt<0 || dt < min_dt)) min_dt = dt; + } + return min_dt; + } + + void MCParticleTree::dump() const + { + auto const& primary_v = PrimaryArray(); + for(size_t idx=0; idx& mctrack_v, + const std::vector& mcshower_v) + { + size_t old_size = _primary_v.size(); + _primary_v.clear(); + _primary_v.reserve(old_size); + if(_used_mctrack_v.size() <= mctrack_v.size()) + _used_mctrack_v.resize(mctrack_v.size()); + if(_used_mcshower_v.size() <= mcshower_v.size()) + _used_mcshower_v.resize(mcshower_v.size()); + + for(auto& used : _used_mctrack_v ) used = 0; + for(auto& used : _used_mcshower_v) used = 0; + + // + // Register primaries + // + DefinePrimary(mctrack_v,mcshower_v); + + // + // Register secondaries + // + DefineSecondary(mctrack_v,mcshower_v); + EstimateSecondary(mctrack_v,mcshower_v); + + // + // Report + // + if(logger().level() <= larcv::msg::kINFO) { + std::stringstream ss; + for(size_t primary_idx=0; primary_idx<_primary_v.size(); ++primary_idx) { + + auto const& primary = _primary_v[primary_idx]; + + ss << " Primary " << primary_idx << " Source " << (int)(primary.source_type) << " @ " << primary.source_index + << " ... PDG " << primary.pdg << " TrackID " << primary.track_id + << " with " << primary.daughter_v.size() << " children" + << std::endl; + + for(size_t child_idx=0; child_idx& mctrack_v, + const std::vector& mcshower_v) + { + for(size_t track_idx=0; track_idx& mctrack_v, + const std::vector& mcshower_v) + { + size_t used_count_mcshower = 0; + size_t used_count_mctrack = 0; + for(auto const& v : _used_mctrack_v ) if(v) ++used_count_mctrack; + for(auto const& v : _used_mcshower_v) if(v) ++used_count_mcshower; + size_t last_used_count_mctrack = larcv::kINVALID_SIZE; + size_t last_used_count_mcshower = larcv::kINVALID_SIZE; + + while(used_count_mcshower != last_used_count_mcshower || + used_count_mctrack != last_used_count_mctrack) { + + // Update "last" counter + last_used_count_mctrack = used_count_mctrack; + last_used_count_mcshower = used_count_mcshower; + + // Scan tracks for exact parentage connection + for(size_t track_idx=0; track_idx& mctrack_v, + const std::vector& mcshower_v) + { + if(_dt_max <=0) return; + + double primary_min_time = 1.e20; + double primary_max_time = 0.; + for(auto const& primary : _primary_v) { + if(primary.start.T() < primary_min_time) primary_min_time = primary.start.T(); + if(primary.end.T() > primary_max_time) primary_max_time = primary.end.T(); + } + + for(size_t track_idx=0; track_idx " << primary_max_time << ")" + << std::endl; + continue; + } + size_t primary_idx = larcv::kINVALID_SIZE; + double min_dt = 1e20; + for(size_t idx=0; idx<_primary_v.size(); ++idx) { + auto const& primary = _primary_v[idx]; + auto const dt = primary.dt(node); + if(dt<0) continue; + if(dt < min_dt) { + min_dt = dt; + primary_idx = idx; + } + } + if(min_dt > _dt_max) continue; + LARCV_INFO() << "Associating (time-approx) MCTrack (index " << track_idx + << " PDG " << track.PdgCode() << " Origin " << track.Origin() + << ") with primary (index " << primary_idx + << " PDG " << _primary_v[primary_idx].part.PdgCode() + << " Origin " << _primary_v[primary_idx].origin + << ")" << std::endl; + _primary_v[primary_idx].daughter_v.emplace_back(std::move(node)); + _used_mctrack_v[track_idx] = 1; + } + + for(size_t shower_idx=0; shower_idx " << primary_max_time << ")" + << std::endl; + continue; + } + size_t primary_idx = larcv::kINVALID_SIZE; + double min_dt = 1e20; + for(size_t idx=0; idx<_primary_v.size(); ++idx) { + auto const& primary = _primary_v[idx]; + auto const dt = primary.dt(node); + if(dt<0) continue; + if(dt < min_dt) { + min_dt = dt; + primary_idx = idx; + } + } + LARCV_INFO() << "Associating (time-approx) MCShower (index " << shower_idx + << " PDG " << shower.PdgCode() << " Origin " << shower.Origin() + << ") with primary (index " << primary_idx + << " PDG " << _primary_v[primary_idx].part.PdgCode() + << " Origin " << _primary_v[primary_idx].origin + << ")" << std::endl; + if(min_dt > _dt_max) continue; + _primary_v[primary_idx].daughter_v.emplace_back(std::move(node)); + _used_mcshower_v[shower_idx] = 1; + } + } + +} + +#endif diff --git a/arxiv/MCParticleTree.h b/arxiv/MCParticleTree.h new file mode 100644 index 0000000..1b0e6cf --- /dev/null +++ b/arxiv/MCParticleTree.h @@ -0,0 +1,145 @@ +/** + * \file MCParticleTree.h + * + * \ingroup MeatSlicer + * + * \brief Class def header for a class MCParticleTree + * + * @author kazuhiro + */ + +/** \addtogroup MeatSlicer + + @{*/ +#ifndef MCPARTICLETREE_H +#define MCPARTICLETREE_H + +#include +#include "larcv/core/DataFormat/Vertex.h" +#include "larcv/core/DataFormat/Particle.h" +#include "FMWKInterface.h" +#include "larcv/core/Base/larcv_base.h" +namespace supera { + + class MCNode { + public: + enum class SourceType_t { + kMCTrack, + kMCShower, + kUnknown + }; + + public: + MCNode() : origin(0) + , pdg(0) + , track_id(larcv::kINVALID_SIZE) + , start() + , end() + , source_index(larcv::kINVALID_SIZE) + , source_type(SourceType_t::kUnknown) + {} + ~MCNode(){} + + unsigned short origin; + int pdg; + size_t track_id; + larcv::Vertex start; + larcv::Vertex end; + size_t source_index; + SourceType_t source_type; + + std::string dump() const; + }; + + class MCRoot : public MCNode{ + public: + MCRoot() : MCNode() + , daughter_v() + {} + MCRoot(const MCNode& node) : MCNode(node) + , daughter_v() + {} + ~MCRoot(){} + /// Check if supplied parent track id belongs to this tree + bool is_daughter(const size_t& parent_id) const; + /** + Check if supplied node belongs to this Root via 0) start-start, 1) end-start matching + */ + bool is_daughter(const larcv::Vertex& start) const; + /** + Compute the smallest positive dT among any particle in this tree and the provided node + */ + double dt(const MCNode& node) const; + + std::vector daughter_v; + ::larcv::Particle part; + + }; + + /** + \class MCParticleTree + User defined class MCParticleTree ... these comments are used to generate + doxygen documentation! + */ + class MCParticleTree : public larcv::larcv_base { + + public: + + /// Default constructor + MCParticleTree() : larcv::larcv_base("MCParticleTree") + , _origin_filter(0) + {} + + /// Default destructor + ~MCParticleTree(){} + + void configure(const Config_t& cfg) + { + set_verbosity((::larcv::msg::Level_t)(cfg.get("Verbosity",logger().level()))); + _dt_max = cfg.get("DTMax"); + } + + void Register(const std::vector& mctrack_v, + const std::vector& mcshower_v); + + void FilterOrigin(unsigned short flag) + { _origin_filter = flag; } + + const std::vector& PrimaryArray() const + { return _primary_v; } + + void dump() const; + + private: + + std::vector _primary_v; + std::vector _used_mctrack_v; + std::vector _used_mcshower_v; + unsigned short _origin_filter; + double _dt_max; + + MCNode FillNode(const supera::LArMCTrack_t& mct); + + MCNode FillNode(const supera::LArMCShower_t& mcs); + + size_t FindPrimary(const larcv::Vertex& start, + const size_t parent_id, + const size_t ancestor_id) const; + + size_t FindPrimary(const size_t parent_id, + const size_t ancestor_id) const; + + void DefinePrimary(const std::vector& mctrack_v, + const std::vector& mcshower_v); + + void DefineSecondary(const std::vector& mctrack_v, + const std::vector& mcshower_v); + + void EstimateSecondary(const std::vector& mctrack_v, + const std::vector& mcshower_v); + + }; +} +#endif +/** @} */ // end of doxygen group + diff --git a/arxiv/SuperaKeyPointCluster.cxx b/arxiv/SuperaKeyPointCluster.cxx new file mode 100644 index 0000000..c70746e --- /dev/null +++ b/arxiv/SuperaKeyPointCluster.cxx @@ -0,0 +1,247 @@ +#ifndef __SUPERAKEYPOINTCLUSTER_CXX__ +#define __SUPERAKEYPOINTCLUSTER_CXX__ + +#include "SuperaKeyPointCluster.h" +#include "ImageMetaMakerFactory.h" +#include "PulledPork3DSlicer.h" +#include "DataFormat/EventPixel2D.h" +#include "DataFormat/EventROI.h" + +namespace larcv { + + static SuperaKeyPointClusterProcessFactory __global_SuperaKeyPointClusterProcessFactory__; + + SuperaKeyPointCluster::SuperaKeyPointCluster(const std::string name) + : SuperaBase(name) + {} + + void SuperaKeyPointCluster::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsPixel2D::configure(cfg); + supera::ImageMetaMaker::configure(cfg); + + _in_roi_label = cfg.get("InputROILabel"); + _apply_sce = cfg.get("ApplySCE"); + _row_pad = cfg.get("RowPad"); + _col_pad = cfg.get("ColPad"); + + _cluster_primary_start = cfg.get("UsePrimaryStart",true); + _cluster_secondary_start = cfg.get("UseSecondaryStart",true); + _cluster_scattering = cfg.get("UseScattering",false); + } + + void SuperaKeyPointCluster::initialize() + { SuperaBase::initialize(); } + + larcv::Vertex SuperaKeyPointCluster::GetPoint(const supera::LArMCStep_t& step) + { + static double xyz[3]; + static const double drift_velocity = ::supera::DriftVelocity() * 1.0e-3; // make it cm/ns + xyz[0] = step.X(); + xyz[1] = step.Y(); + xyz[2] = step.Z(); + if(_apply_sce) supera::ApplySCE(xyz); + + larcv::Vertex pt(xyz[0],xyz[1],xyz[2], + (double)(step.T() + (xyz[0] / drift_velocity))); + + return pt; + } + + bool SuperaKeyPointCluster::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + if(supera::PulledPork3DSlicer::Is(supera::ImageMetaMaker::MetaMakerPtr())) { + auto ptr = (supera::PulledPork3DSlicer*)(supera::ImageMetaMaker::MetaMakerPtr()); + ptr->ClearEventData(); + ptr->AddConstraint(LArData()); + ptr->GenerateMeta(LArData(),TimeOffset()); + } + + auto ev_pixel2d = (EventPixel2D*)(mgr.get_data(kProductPixel2D,OutPixel2DLabel())); + if(!ev_pixel2d) { + LARCV_CRITICAL() << "Failed to create Pixel2D output data container w/ label " << OutPixel2DLabel() << std::endl; + throw larbys(); + } + + auto ev_roi = (EventROI*)(mgr.get_data(kProductROI,_in_roi_label)); + if(!ev_roi) { + LARCV_CRITICAL() << "Failed to fetch an input ROI by " << _in_roi_label << std::endl; + throw larbys(); + } + + std::set primary_start_s; + std::set secondary_start_s; + std::set scattering_s; + + for(auto const& mctrack : LArData()) { + + if(mctrack.size()<2) continue; + + auto start = GetPoint(mctrack.Start()); + if(mctrack.TrackID() == mctrack.MotherTrackID()) { + if(_cluster_primary_start) { + LARCV_INFO() << "Primary MCTrack (PDG " << mctrack.PdgCode() << ") start @ (" + << start.X() << "," << start.Y() << "," << start.Z() << ")" + << " @ G4 Time = " << start.T() << " [ns]" << std::endl; + primary_start_s.emplace(std::move(start)); + } + } + else { + if(_cluster_secondary_start) { + LARCV_INFO() << "Secondary MCTrack (PDG " << mctrack.PdgCode() << ") start @ (" + << start.X() << "," << start.Y() << "," << start.Z() << ")" + << " @ G4 Time = " << start.T() << " [ns]" << std::endl; + secondary_start_s.emplace(std::move(start)); + } + } + if(_cluster_scattering) { + for(auto const& step : mctrack) { + if(step.T() == mctrack.Start().T()) continue; + auto pt = GetPoint(step); + LARCV_INFO() << "Scattering @ (" + << pt.X() << "," << pt.Y() << "," << pt.Z() << ")" + << " @ G4 Time = " << pt.T() << " [ns]" << std::endl; + scattering_s.emplace(std::move(pt)); + } + } + } + + for(auto const& mcshower : LArData()) { + + if(mcshower.DetProfile().E()<=0) continue; + + auto start = GetPoint(mcshower.Start()); + + if(mcshower.TrackID() == mcshower.MotherTrackID()) { + if(_cluster_primary_start) { + LARCV_INFO() << "Primary MCShower (PDG " << mcshower.PdgCode() << ") start @ (" + << start.X() << "," << start.Y() << "," << start.Z() << ")" + << " @ G4 Time = " << start.T() << " [ns]" << std::endl; + primary_start_s.emplace(std::move(start)); + } + } + else { + if(_cluster_secondary_start) { + LARCV_INFO() << "Primary MCShower (PDG " << mcshower.PdgCode() << ") start @ (" + << start.X() << "," << start.Y() << "," << start.Z() << ")" + << " @ G4 Time = " << start.T() << " [ns]" << std::endl; + secondary_start_s.emplace(std::move(start)); + } + } + if(_cluster_secondary_start) { + if(mcshower.Start().T() != mcshower.DetProfile().T()) { + auto pt = GetPoint(mcshower.DetProfile()); + LARCV_INFO() << "DetProfile @ (" + << pt.X() << "," << pt.Y() << "," << pt.Z() << ")" + << " @ G4 Time = " << pt.T() << " [ns]" << std::endl; + secondary_start_s.emplace(std::move(pt)); + } + } + } + + auto meta_v = Meta(); + for(size_t plane=0; planeEmplace( plane, std::move( primary_start_pcluster_v.at(plane) ), meta ); + ev_pixel2d->Emplace( plane, std::move( secondary_start_pcluster_v.at(plane) ), meta ); + ev_pixel2d->Emplace( plane, std::move( scattering_pcluster_v.at(plane) ), meta ); + + } + return true; + } + + std::vector + SuperaKeyPointCluster::CreateCluster(const std::vector& meta_v, + const std::set& pt_s, + const unsigned short val, + const int time_offset) + { + + double xyz[3]; + std::vector res_v; + res_v.resize(meta_v.size()); + + static std::vector > data_v; + data_v.resize(meta_v.size()); + + for(size_t plane=0; plane " << meta.max_x() << std::endl; + LARCV_DEBUG() << tick_float << " ... " << meta.min_y() << " => " << meta.max_y() << std::endl; + if(wire_float < meta.min_x() || meta.max_x() < wire_float) continue; + if(tick_float < meta.min_y() || meta.max_y() < tick_float) continue; + + auto tick = meta.row(tick_float); + auto wire = meta.col(wire_float); + + LARCV_DEBUG() << "Masking around (tick,wire) = (" << tick << "," << wire << ")" << std::endl; + + for(int row=((int)tick - (int)_row_pad); row<=((int)tick + (int)(_row_pad)); ++row) { + for(int col=((int)wire - (int)_col_pad); col<=((int)wire + (int)_col_pad); ++col) { + if(row<0 || row >= (int)(meta.rows())) continue; + if(col<0 || col >= (int)(meta.cols())) continue; + LARCV_DEBUG() << " Registering (row,col) = (" << row << "," << col << ") w/ value " << val << std::endl; + auto index = meta.index((size_t)row,(size_t)col); + if(data[index] < val) data[index] = val; + } + } + } + + auto& res = res_v[plane]; + for(size_t index=0; index + CreateCluster(const std::vector& meta_v, + const std::set& pt_s, + const unsigned short val, + const int time_offset); + + std::string _in_roi_label; + bool _apply_sce; + size_t _row_pad; + size_t _col_pad; + bool _cluster_primary_start; + bool _cluster_secondary_start; + bool _cluster_scattering; + + }; + + /** + \class larcv::SuperaKeyPointClusterFactory + \brief A concrete factory class for larcv::SuperaKeyPointCluster + */ + class SuperaKeyPointClusterProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaKeyPointClusterProcessFactory() { ProcessFactory::get().add_factory("SuperaKeyPointCluster",this); } + /// dtor + ~SuperaKeyPointClusterProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaKeyPointCluster(instance_name); } + }; + +} +#endif + +/** @} */ // end of doxygen group + diff --git a/arxiv/SuperaMCPCluster.cxx b/arxiv/SuperaMCPCluster.cxx new file mode 100644 index 0000000..74ba830 --- /dev/null +++ b/arxiv/SuperaMCPCluster.cxx @@ -0,0 +1,143 @@ +#ifndef __SUPERAMCPCLUSTER_CXX__ +#define __SUPERAMCPCLUSTER_CXX__ + +#include "SuperaMCPCluster.h" +#include "DataFormat/EventROI.h" +#include "DataFormat/EventPixel2D.h" +#include "LAr2Image.h" + +namespace larcv { + + static SuperaMCPClusterProcessFactory __global_SuperaMCPClusterProcessFactory__; + + SuperaMCPCluster::SuperaMCPCluster(const std::string name) + : SuperaMCROI(name) + {} + + void SuperaMCPCluster::configure(const PSet& cfg) + { + SuperaMCROI::configure(cfg); + supera::ParamsPixel2D::configure(cfg); + } + + void SuperaMCPCluster::initialize() + { SuperaMCROI::initialize(); } + + bool SuperaMCPCluster::process(IOManager& mgr) + { + SuperaMCROI::process(mgr); + + auto ev_pixel2d = (EventPixel2D*)(mgr.get_data(kProductPixel2D,OutPixel2DLabel())); + if(!ev_pixel2d) { + LARCV_CRITICAL() << "Failed to create an output pixel2d w/ label " << OutPixel2DLabel() << std::endl; + throw larbys(); + } + + auto ev_roi = (EventROI*)(mgr.get_data(kProductROI,OutROILabel())); + if(!ev_roi) { + LARCV_CRITICAL() << "Failed to fetch ROI (needs to be created) by " << OutROILabel() << std::endl; + throw larbys(); + } + + std::vector trackid2cluster; + auto const& roi2mcnode_vv = ROI2MCNode(); + auto const& primary_v = ParticleTree().PrimaryArray(); + + // check ROI length + if(ev_roi->ROIArray().size() != roi2mcnode_vv.size()) { + LARCV_CRITICAL() << "ROI2MCNode() return length not same as EventROI!" << std::endl; + throw larbys(); + } + + auto const& mcshower_v = LArData(); + + for(size_t roi_idx=0; roi_idx(), + trackid2cluster, + TimeOffset()); + + auto const& roi_v = ev_roi->ROIArray(); + if(roi_v.size() < pxcluster_vv.size()) { + LARCV_CRITICAL() << "# PixelCluster (" << pxcluster_vv.size() + << ") is greater than # ROI (" << roi_v.size() << ")!" << std::endl; + throw larbys(); + } + + auto meta_v = Meta(); + for(auto& meta: meta_v) meta.update(meta.rows() / RowCompressionFactor().at(meta.plane()), + meta.cols() / ColCompressionFactor().at(meta.plane())); + + for(size_t roi_idx=0; roi_idxEmplace(plane, std::move(pxcluster_vv[roi_idx][plane]), meta_v.at(plane)); + + } + + return true; + } + + void SuperaMCPCluster::finalize() + { SuperaMCROI::finalize(); } + +} +#endif diff --git a/arxiv/SuperaMCPCluster.h b/arxiv/SuperaMCPCluster.h new file mode 100644 index 0000000..2cc3f86 --- /dev/null +++ b/arxiv/SuperaMCPCluster.h @@ -0,0 +1,66 @@ +/** + * \file SuperaMCPCluster.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaMCPCluster + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAMCPCLUSTER_H__ +#define __SUPERAMCPCLUSTER_H__ +#include "SuperaMCROI.h" +#include "ParamsPixel2D.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaMCPCluster ... these comments are used to generate + doxygen documentation! + */ + class SuperaMCPCluster : public SuperaMCROI, + public supera::ParamsPixel2D { + + public: + + /// Default constructor + SuperaMCPCluster(const std::string name="SuperaMCPCluster"); + + /// Default destructor + ~SuperaMCPCluster(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + }; + + /** + \class larcv::SuperaMCPClusterFactory + \brief A concrete factory class for larcv::SuperaMCPCluster + */ + class SuperaMCPClusterProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaMCPClusterProcessFactory() { ProcessFactory::get().add_factory("SuperaMCPCluster",this); } + /// dtor + ~SuperaMCPClusterProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaMCPCluster(instance_name); } + }; + +} +#endif +//#endif +//#endif +/** @} */ // end of doxygen group + diff --git a/arxiv/SuperaMCROI.cxx b/arxiv/SuperaMCROI.cxx new file mode 100644 index 0000000..be1beb0 --- /dev/null +++ b/arxiv/SuperaMCROI.cxx @@ -0,0 +1,480 @@ +#ifndef __SUPERAMCPARTICLE_CXX__ +#define __SUPERAMCPARTICLE_CXX__ + +#include "SuperaMCParticle.h" +#include "ImageMetaMakerFactory.h" +#include "PulledPork3DSlicer.h" +#include "larcv/core/DataFormat/EventParticle.h" +#include "LAr2Image.h" + +namespace larcv { + + static SuperaMCParticleProcessFactory __global_SuperaMCParticleProcessFactory__; + + SuperaMCParticle::SuperaMCParticle(const std::string name) + : SuperaBase(name) + {} + + const std::vector >& SuperaMCParticle::Particle2MCNode(int part_index) const + { + if(part_index >= (int)(_part2mcnode_vv.size())) + throw larbys("Invalid Particle index requested"); + + return _part2mcnode_vv[part_index]; + } + + void SuperaMCParticle::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsParticle::configure(cfg); + supera::ImageMetaMaker::configure(cfg); + + _store_part = cfg.get("StoreParticle",true); + _store_g4_secondary_part = cfg.get("StoreG4SecondaryParticle",true); + _store_g4_primary_part = cfg.get("StoreG4PrimaryParticle",true); + _mcpt.configure(cfg.get("MCParticleTree")); + _mcpart_maker.configure(cfg.get("MCParticleMaker")); + + _pass_origin = cfg.get("Origin"); + _mcpt.FilterOrigin(_pass_origin); + + _filter_pdg = cfg.get >("FilterTargetPDG"); + _filter_min_einit = cfg.get >("FilterTargetInitEMin"); + _filter_min_edep = cfg.get >("FilterTargetDepEMin"); + + if(_filter_pdg.size() != _filter_min_einit.size()) { + LARCV_CRITICAL() << "FilterTargetPDG and FilterTargetInitEMin not the same length!" << std::endl; + throw larbys(); + } + + if(_filter_pdg.size() != _filter_min_edep.size()) { + LARCV_CRITICAL() << "FilterTargetPDG and FilterTargetDepEMin not the same length!" << std::endl; + throw larbys(); + } + + _shower_min_einit = cfg.get("ShowerInitEMin"); + _shower_min_edep = cfg.get("ShowerDepEMin"); + + _track_min_einit = cfg.get("TrackInitEMin"); + _track_min_edep = cfg.get("TrackDepEMin"); + + _filter_min_cols = cfg.get("FilterParticleMinCols"); + _filter_min_rows = cfg.get("FilterParticleMinRows"); + + } + + void SuperaMCParticle::initialize() + { + SuperaBase::initialize(); + } + + bool SuperaMCParticle::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + if(supera::PulledPork3DSlicer::Is(supera::ImageMetaMaker::MetaMakerPtr())) { + auto ptr = (supera::PulledPork3DSlicer*)(supera::ImageMetaMaker::MetaMakerPtr()); + ptr->ClearEventData(); + ptr->AddConstraint(LArData()); + ptr->GenerateMeta(LArData(),TimeOffset()); + } + + auto const& meta_v = Meta(); + + if(meta_v.empty()) { + LARCV_CRITICAL() << "Meta not created!" << std::endl; + throw larbys(); + } + auto ev_part = (EventParticle*)(mgr.get_data("part",OutParticleLabel())); + if(!ev_part) { + LARCV_CRITICAL() << "Output part could not be created!" << std::endl; + throw larbys(); + } + if(!(ev_part->ParticleArray().empty())) { + LARCV_CRITICAL() << "Output part array not empty!" << std::endl; + throw larbys(); + } + + LARCV_INFO() << "Running MCParticleTree::Register" << std::endl; + _mcpt.Register(LArData(),LArData()); + _mcpt.dump(); + + auto primary_v = _mcpt.PrimaryArray(); + LARCV_INFO() << "Found " << primary_v.size() << " primary particles" << std::endl; + + std::vector empty_sch_v; + + _part_v.clear(); + _part2mcnode_vv.clear(); + + for(size_t primary_idx = 0; primary_idx < primary_v.size(); ++primary_idx) { + + auto& primary = primary_v[primary_idx]; + + // filter out primary of certain origin, if specified + if(_pass_origin && primary.origin != _pass_origin) { + LARCV_INFO() << "Skipping a primary " << primary_idx + << " (origin type " << primary.origin + << " PDG " << primary.pdg + << ") with " << primary.daughter_v.size() << " children" + << std::endl; + continue; + } + + if(!FilterNode(primary)) { + LARCV_INFO() << "Skipping a primary (TrackID " << primary.track_id + << " Origin " << primary.origin + << " PDG " << primary.pdg + << ") due to FilterNode()" << std::endl; + continue; + } + + if(LArDataLabel(supera::LArDataType_t::kLArSimCh_t).empty()) + primary.part = MakeParticle(primary,empty_sch_v); + else + primary.part = MakeParticle(primary,LArData()); + + LARCV_INFO() << "Analyzing primary " << primary_idx << " PDG " << primary.part.PdgCode() + << " Origin " << primary.origin + << " PDG << " << primary.pdg + << " with " << primary.daughter_v.size() << " children" << std::endl; + + std::vector sec_part_v; + std::vector sec_idx_v; + for(size_t daughter_idx=0; daughter_idx()); + }catch(const larcv::larbys& err) { + LARCV_NORMAL() << "Skipping a secondary (PDG,TrackID) = (" + << daughter.pdg << "," << daughter.track_id << ") as it could not be turned into Particle" << std::endl; + continue; + } + if( (_filter_min_rows>0 || _filter_min_cols>0) && part.BB().empty() ) { + LARCV_INFO() << "Skipping a daughter " << daughter_idx + << " (TrackID " << daughter.track_id + << " Origin " << daughter.origin + << " PDG " << part.PdgCode() << ") due to the size of Particle" << std::endl; + continue; + } + bool skip=false; + for(auto const& bb : part.BB()) { + if(bb.rows() <= _filter_min_rows && bb.cols() <= _filter_min_cols) { + LARCV_INFO() << "Skipping a daughter " << daughter_idx + << " (TrackID " << daughter.track_id + << " Origin " << daughter.origin + << " PDG " << part.PdgCode() << ") due to the size of Particle " + << "(row,col) = (" << bb.rows() << "," << bb.cols() << ")" + << std::endl; + skip=true; + break; + } + } + if(skip) continue; + LARCV_INFO() << "Registering a daughter " << daughter_idx + << " (TrackID " << daughter.track_id + << " Origin " << daughter.origin + << " PDG " << part.PdgCode() << ")" << std::endl; + sec_part_v.push_back(part); + sec_idx_v.push_back(daughter_idx); + } + + LARCV_INFO() << "Updating primary Particle with " << sec_part_v.size() << " children" << std::endl; + UpdatePrimaryParticle(primary.part, sec_part_v); + + if( (_filter_min_rows>0 || _filter_min_cols>0) && primary.part.BB().empty() ) + continue; + bool skip=false; + for(auto const& bb : primary.part.BB()) { + if(bb.rows() >= _filter_min_rows && bb.cols() >= _filter_min_cols) + continue; + skip=true; + break; + } + if(skip) continue; + + std::vector > part2mcnode_v; + part2mcnode_v.clear(); + + // + // Register primary Particle + // + LARCV_INFO() << "Storing primary Particle (PDG " << primary.part.PdgCode() + << " Shape " << primary.part.Shape() + << " MCTIndex " << primary.part.MCTIndex() + << " MCSTIndex) " << primary.part.MCSTIndex() + << std::endl; + + _part_v.push_back(primary.part); + + // Record incorporated mcnode + part2mcnode_v.emplace_back(primary_idx, larcv::kINVALID_SIZE); + for(size_t daughter_idx=0; daughter_idxEmplace(std::move(_part_v)); + + return true; + } + + bool SuperaMCParticle::FilterNode(const supera::MCNode& node) const + { + if(node.source_type == supera::MCNode::SourceType_t::kMCTruth) { + if(_pass_origin && node.origin != _pass_origin) + return false; + }else if(node.source_type == supera::MCNode::SourceType_t::kMCTrack) { + auto const& mctrack = LArData()[node.source_index]; + LARCV_DEBUG() << "MCTrack InitE " << mctrack.Start().E() << " ... DepE " + << (mctrack.size() >1 ? mctrack.front().E() - mctrack.back().E() : 0) << std::endl; + if(mctrack.Start().E() < _track_min_einit) return false; + if(_track_min_edep > 0) { + if(mctrack.size()<2) return false; + if( (mctrack.front().E() - mctrack.back().E()) < _track_min_edep ) return false; + } + for(size_t filter_idx=0; filter_idx<_filter_pdg.size(); ++filter_idx) { + auto const& pdg = _filter_pdg[filter_idx]; + if(pdg != mctrack.PdgCode()) continue; + auto const& filter_min_einit = _filter_min_einit[filter_idx]; + if(mctrack.Start().E() < filter_min_einit) return false; + auto const& filter_min_edep = _filter_min_edep[filter_idx]; + if(filter_min_edep > 0) { + if(mctrack.size()<2) return false; + if( (mctrack.front().E() - mctrack.back().E()) < filter_min_edep ) return false; + } + } + }else if(node.source_type == supera::MCNode::SourceType_t::kMCShower) { + auto const& mcshower = LArData()[node.source_index]; + LARCV_DEBUG() << "MCShower InitE " << mcshower.Start().E() << " ... DepE " + << mcshower.DetProfile().E() << std::endl; + if(mcshower.Start().E() < _shower_min_einit) return false; + if(mcshower.DetProfile().E() < _shower_min_edep) return false; + for(size_t filter_idx=0; filter_idx<_filter_pdg.size(); ++filter_idx) { + auto const& pdg = _filter_pdg[filter_idx]; + if(pdg != mcshower.PdgCode()) continue; + auto const& filter_min_einit = _filter_min_einit[filter_idx]; + if(mcshower.Start().E() < filter_min_einit) return false; + auto const& filter_min_edep = _filter_min_edep[filter_idx]; + if( mcshower.DetProfile().E() < filter_min_edep) return false; + } + } + return true; + } + + larcv::Particle SuperaMCParticle::MakeParticle(const supera::MCNode& node, + const std::vector& sch_v) const + { + larcv::Particle res; + if(node.source_type == supera::MCNode::SourceType_t::kMCTruth) + throw larbys("MCTruth type cannot make Particle using MCParticleMaker!"); + else if(node.source_type == supera::MCNode::SourceType_t::kMCTrack) { + auto const& mctrack = LArData().at(node.source_index); + if(sch_v.empty()) res = _mcpart_maker.Particle(mctrack,TimeOffset()); + else res = _mcpart_maker.Particle(mctrack,sch_v,TimeOffset()); + res.MCSTIndex(node.source_index); + } + else if(node.source_type == supera::MCNode::SourceType_t::kMCShower) { + auto const& mcshower = LArData().at(node.source_index); + if(sch_v.empty()) res = _mcpart_maker.Particle(mcshower,TimeOffset()); + else res = _mcpart_maker.Particle(mcshower,sch_v,TimeOffset()); + res.MCSTIndex(node.source_index); + }else + throw larbys("Unexpected SourceType_t!"); + + // format Particle + std::vector bb_v; + for(size_t plane=0; plane& sec_part_v) const + { + LARCV_DEBUG() << "start" << std::endl; + + std::map sum_part_m; + double energy_deposit = 0; + // register primary BB + for (auto const& bb : pri_part.BB()) { + if(pri_part.EnergyDeposit()>0) energy_deposit += pri_part.EnergyDeposit(); + if (!(bb.height() > 1 && bb.width() > 1)) continue; + auto iter = sum_part_m.find(bb.plane()); + if (iter == sum_part_m.end()) + sum_part_m[bb.plane()] = bb; + else + (*iter).second = (*iter).second.inclusive(bb); + } + + // Next, secondary BB + for (auto& sec_part : sec_part_v) { + energy_deposit += sec_part.EnergyDeposit(); + // loop over plane-by-plane ImageMeta + for (auto const& bb : sec_part.BB()) { + if (!(bb.height() > 1 && bb.width() > 1)) continue; + auto iter = sum_part_m.find(bb.plane()); + if (iter == sum_part_m.end()) + sum_part_m[bb.plane()] = bb; + else + (*iter).second = (*iter).second.inclusive(bb); + } + sec_part.MCTIndex(pri_part.MCTIndex()); + } + + std::vector bb_v; + bb_v.reserve(sum_part_m.size()); + + for (auto const& plane_part : sum_part_m) { + if(bb_v.size() <= plane_part.first) + bb_v.resize(plane_part.first+1); + bb_v[plane_part.first] = plane_part.second; + LARCV_INFO() << "Updated primary Particle plane " << plane_part.first << " ... " << plane_part.second.dump(); + } + + pri_part.EnergyDeposit(energy_deposit); + + pri_part.SetBB(bb_v); + } + + larcv::ImageMeta SuperaMCParticle::FormatMeta(const larcv::ImageMeta& part_image, + const larcv::ImageMeta& event_image) const + { + + LARCV_DEBUG() << "Before format " << part_image.dump(); + + const size_t modular_row = event_image.height() / event_image.rows(); + const size_t modular_col = event_image.width() / event_image.cols(); + + if (event_image.rows() < modular_row || event_image.cols() < modular_col) { + LARCV_ERROR() << "Event image too small to format Particle!" << std::endl; + throw larbys(); + } + double min_x = (part_image.min_x() < event_image.min_x() ? event_image.min_x() : part_image.min_x() ); + double max_y = (part_image.max_y() > event_image.max_y() ? event_image.max_y() : part_image.max_y() ); + double width = (part_image.width() + min_x > event_image.max_x() ? event_image.max_x() - min_x : part_image.width()); + double height = (max_y - part_image.height() < event_image.min_y() ? max_y - event_image.min_y() : part_image.height()); + size_t rows = height / part_image.pixel_height(); + size_t cols = width / part_image.pixel_width(); + + if (modular_col > 1 && cols % modular_col) { + int npixels = (modular_col - (cols % modular_col)); + if (event_image.width() < (width + npixels * part_image.pixel_width())) npixels -= modular_col; + cols += npixels; + width += part_image.pixel_width() * npixels; + if (npixels > 0) { + // If expanded, make sure it won't go across event_image boundary + if ( (min_x + width) > event_image.max_x() ) { + LARCV_DEBUG() << "X: " << min_x << " => " << min_x + width + << " exceeds event boundary " << event_image.max_x() << std::endl; + min_x = event_image.max_x() - width; + } else if (min_x < event_image.min_x()) { + LARCV_DEBUG() << "X: " << min_x << " => " << min_x + width + << " exceeds event boundary " << event_image.min_x() << std::endl; + min_x = event_image.min_x(); + } + } + } + + if (modular_row > 1 && rows % modular_row) { + int npixels = (modular_row - (rows % modular_row)); + if (event_image.height() < (height + npixels * part_image.pixel_height())) npixels -= modular_row; + rows += npixels; + height += part_image.pixel_height() * npixels; + if (npixels > 0) { + // If expanded, make sure it won't go across event_image boundary + if ( (max_y - height) < event_image.min_y() ) { + LARCV_DEBUG() << "Y: " << max_y - height << " => " << max_y + << " exceeds event boundary " << event_image.min_y() << std::endl; + max_y = event_image.min_y() + height; + } else if (max_y > event_image.max_y()) { + LARCV_DEBUG() << "Y: " << max_y - height << " => " << max_y + << " exceeds event boundary " << event_image.max_y() << std::endl; + max_y = event_image.max_y(); + } + } + } + LARCV_INFO() << "Creating ImageMeta Width=" << width + << " Height=" << height + << " NRows=" << rows / modular_row + << " NCols=" << cols / modular_col + << " Origin @ (" << min_x << "," << max_y << ")" << std::endl; + larcv::ImageMeta res(width, height, + rows / modular_row, cols / modular_col, + min_x, max_y, + part_image.plane()); + + LARCV_DEBUG() << "Event image " << event_image.dump(); + + LARCV_DEBUG() << "After format " << res.dump(); + /* + res = event_image.overlap(res); + + LARCV_DEBUG() << "After overlap " << res.dump(); + */ + return res; + } + + void SuperaMCParticle::finalize() + {} + +} +#endif diff --git a/arxiv/SuperaMCROI.h b/arxiv/SuperaMCROI.h new file mode 100644 index 0000000..9be28bb --- /dev/null +++ b/arxiv/SuperaMCROI.h @@ -0,0 +1,114 @@ +/** + * \file SuperaMCParticle.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaMCParticle + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERAMCPARTICLE_H__ +#define __SUPERAMCPARTICLE_H__ +//#ifndef __CINT__ +//#ifndef __CLING__ +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "MCParticleTree.h" +#include "MCROIMaker.h" +#include "ImageMetaMaker.h" +#include "ParamsROI.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaMCParticle ... these comments are used to generate + doxygen documentation! + */ + class SuperaMCParticle : public SuperaBase, + public supera::ParamsROI, + public supera::ImageMetaMaker { + + public: + + /// Default constructor + SuperaMCParticle(const std::string name="SuperaMCParticle"); + + /// Default destructor + ~SuperaMCParticle(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + bool StoreG4SecondaryROI() const { return _store_g4_secondary_roi; } + + bool StoreG4PrimaryROI() const { return _store_g4_primary_roi; } + + const std::vector >& Particle2MCNode(int roi_index) const; + + const std::vector > >& + Particle2MCNode() const { return _roi2mcnode_vv; } + + const supera::MCParticleTree& ParticleTree() const { return _mcpt; } + + private: + + bool _store_part; + bool _store_g4_primary_part; + bool _store_g4_secondary_part; + std::vector _part_v; + supera::MCParticleTree _mcpt; + supera::MCParticleMaker _mcpart_maker; + std::vector > > _part2mcnode_vv; + + unsigned short _pass_origin; + std::vector _filter_pdg; + std::vector _filter_min_einit; + std::vector _filter_min_edep; + + double _shower_min_einit; + double _shower_min_edep; + + double _track_min_einit; + double _track_min_edep; + + size_t _filter_min_cols; + size_t _filter_min_rows; + + bool FilterNode(const supera::MCNode& node) const; + larcv::ImageMeta FormatMeta(const larcv::ImageMeta& part_image, + const larcv::ImageMeta& event_image) const; + larcv::Particle MakeParticle(const supera::MCNode& node,const std::vector& sch_v) const; + void UpdatePrimaryParticle(larcv::Particle& pri_part, + std::vector& sec_part_v) const; + }; + + /** + \class larcv::SuperaMCParticleFactory + \brief A concrete factory class for larcv::SuperaMCParticle + */ + class SuperaMCParticleProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaMCParticleProcessFactory() { ProcessFactory::get().add_factory("SuperaMCParticle",this); } + /// dtor + ~SuperaMCParticleProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaMCParticle(instance_name); } + }; + +} +//#endif +//#endif +#endif +/** @} */ // end of doxygen group + diff --git a/arxiv/SuperaSimCh.cxx b/arxiv/SuperaSimCh.cxx new file mode 100644 index 0000000..e9d3be7 --- /dev/null +++ b/arxiv/SuperaSimCh.cxx @@ -0,0 +1,116 @@ +#ifndef __SUPERASIMCH_CXX__ +#define __SUPERASIMCH_CXX__ + +#include "SuperaSimCh.h" +#include "LAr2Image.h" +#include "ImageMetaMakerFactory.h" +#include "PulledPork3DSlicer.h" +#include "DataFormat/EventImage2D.h" +#include "DataFormat/DataFormatUtil.h" +namespace larcv { + + static SuperaSimChProcessFactory __global_SuperaSimChProcessFactory__; + + SuperaSimCh::SuperaSimCh(const std::string name) + : SuperaBase(name) + {} + + void SuperaSimCh::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsImage2D::configure(cfg); + supera::ImageMetaMaker::configure(cfg); + _origin = cfg.get("Origin",0); + } + + void SuperaSimCh::initialize() + {} + + bool SuperaSimCh::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + if(supera::PulledPork3DSlicer::Is(supera::ImageMetaMaker::MetaMakerPtr())) { + auto ptr = (supera::PulledPork3DSlicer*)(supera::ImageMetaMaker::MetaMakerPtr()); + ptr->ClearEventData(); + ptr->AddConstraint(LArData()); + ptr->GenerateMeta(LArData(),TimeOffset()); + } + + auto const& meta_v = Meta(); + + if(meta_v.empty()) { + LARCV_CRITICAL() << "Meta not created!" << std::endl; + throw larbys(); + } + auto ev_image = (EventImage2D*)(mgr.get_data(kProductImage2D,OutImageLabel())); + if(!ev_image) { + LARCV_CRITICAL() << "Output image could not be created!" << std::endl; + throw larbys(); + } + if(!(ev_image->Image2DArray().empty())) { + LARCV_CRITICAL() << "Output image array not empty!" << std::endl; + throw larbys(); + } + + std::vector track2type_v; + for(auto const& mctrack : LArData()) { + + if(_origin && ((unsigned short)(mctrack.Origin())) != _origin) continue; + + if(mctrack.TrackID() >= track2type_v.size()) + track2type_v.resize(mctrack.TrackID()+1,larcv::ROIType_t::kROIUnknown); + track2type_v[mctrack.TrackID()] = larcv::PdgCode2ROIType(mctrack.PdgCode()); + + if(mctrack.MotherTrackID() >= track2type_v.size()) + track2type_v.resize(mctrack.MotherTrackID()+1,larcv::ROIType_t::kROIUnknown); + track2type_v[mctrack.MotherTrackID()] = larcv::PdgCode2ROIType(mctrack.MotherPdgCode()); + + if(mctrack.AncestorTrackID() >= track2type_v.size()) + track2type_v.resize(mctrack.AncestorTrackID()+1,larcv::ROIType_t::kROIUnknown); + track2type_v[mctrack.AncestorTrackID()] = larcv::PdgCode2ROIType(mctrack.AncestorPdgCode()); + } + for(auto const& mcshower : LArData()) { + + if(_origin && ((unsigned short)(mcshower.Origin())) != _origin) continue; + + if(mcshower.TrackID() >= track2type_v.size()) + track2type_v.resize(mcshower.TrackID()+1,larcv::ROIType_t::kROIUnknown); + track2type_v[mcshower.TrackID()] = larcv::PdgCode2ROIType(mcshower.PdgCode()); + + if(mcshower.MotherTrackID() >= track2type_v.size()) + track2type_v.resize(mcshower.MotherTrackID()+1,larcv::ROIType_t::kROIUnknown); + track2type_v[mcshower.MotherTrackID()] = larcv::PdgCode2ROIType(mcshower.MotherPdgCode()); + + if(mcshower.AncestorTrackID() >= track2type_v.size()) + track2type_v.resize(mcshower.AncestorTrackID()+1,larcv::ROIType_t::kROIUnknown); + track2type_v[mcshower.AncestorTrackID()] = larcv::PdgCode2ROIType(mcshower.AncestorPdgCode()); + + for(auto const& daughter_track_id : mcshower.DaughterTrackID()) { + if(daughter_track_id == larcv::kINVALID_UINT) + continue; + if(daughter_track_id >= track2type_v.size()) + track2type_v.resize(daughter_track_id+1,larcv::ROIType_t::kROIUnknown); + track2type_v[daughter_track_id] = track2type_v[mcshower.TrackID()]; + } + } + + auto image_v = supera::SimCh2Image2D(meta_v, track2type_v, LArData(), TimeOffset()); + + for(size_t plane=0; planeEmplace(std::move(image_v)); + + return true; + } + + void SuperaSimCh::finalize() + {} + +} +#endif diff --git a/arxiv/SuperaSimCh.h b/arxiv/SuperaSimCh.h new file mode 100644 index 0000000..7794e0c --- /dev/null +++ b/arxiv/SuperaSimCh.h @@ -0,0 +1,72 @@ +/** + * \file SuperaSimCh.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaSimCh + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERASIMCH_H__ +#define __SUPERASIMCH_H__ +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "ImageMetaMaker.h" +#include "ParamsImage2D.h" +#include "DataFormat/Image2D.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaSimCh ... these comments are used to generate + doxygen documentation! + */ + class SuperaSimCh : public SuperaBase, + public supera::ParamsImage2D, + public supera::ImageMetaMaker { + + public: + + /// Default constructor + SuperaSimCh(const std::string name="SuperaSimCh"); + + /// Default destructor + ~SuperaSimCh(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + private: + + unsigned short _origin; + + }; + + /** + \class larcv::SuperaSimChFactory + \brief A concrete factory class for larcv::SuperaSimCh + */ + class SuperaSimChProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaSimChProcessFactory() { ProcessFactory::get().add_factory("SuperaSimCh",this); } + /// dtor + ~SuperaSimChProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaSimCh(instance_name); } + }; + +} +#endif +/** @} */ // end of doxygen group + diff --git a/arxiv/SuperaSimVoxel3D.cxx b/arxiv/SuperaSimVoxel3D.cxx new file mode 100644 index 0000000..94e8d22 --- /dev/null +++ b/arxiv/SuperaSimVoxel3D.cxx @@ -0,0 +1,141 @@ +#ifndef __SUPERASIMVOXEL3D_CXX__ +#define __SUPERASIMVOXEL3D_CXX__ + +#include "SuperaSimVoxel3D.h" +#include "LAr2Image.h" +#include "ImageMetaMakerFactory.h" +#include "PulledPork3DSlicer.h" +#include "DataFormat/EventVoxel3D.h" +#include "DataFormat/DataFormatUtil.h" +namespace larcv { + + static SuperaSimVoxel3DProcessFactory __global_SuperaSimVoxel3DProcessFactory__; + + SuperaSimVoxel3D::SuperaSimVoxel3D(const std::string name) + : SuperaBase(name) + {} + + void SuperaSimVoxel3D::configure(const PSet& cfg) + { + SuperaBase::configure(cfg); + supera::ParamsVoxel3D::configure(cfg); + supera::ImageMetaMaker::configure(cfg); + _origin = cfg.get("Origin",0); + _voxel_size = cfg.get("VoxelSize",0.9); + _target_plane = cfg.get("TargetPlane",2); + _t0_tick = cfg.get("T0Tick",3200); + } + + void SuperaSimVoxel3D::initialize() + {} + + bool SuperaSimVoxel3D::process(IOManager& mgr) + { + SuperaBase::process(mgr); + + if(supera::PulledPork3DSlicer::Is(supera::ImageMetaMaker::MetaMakerPtr())) { + auto ptr = (supera::PulledPork3DSlicer*)(supera::ImageMetaMaker::MetaMakerPtr()); + ptr->ClearEventData(); + ptr->AddConstraint(LArData()); + ptr->GenerateMeta(LArData(),TimeOffset()); + } + + auto const& meta_v = Meta(); + + if(meta_v.empty()) { + LARCV_CRITICAL() << "Meta not created!" << std::endl; + throw larbys(); + } + + // + // Create output data product container + // + auto ev_voxel3d = (EventVoxel3D*)(mgr.get_data(kProductVoxel3D,OutVoxel3DLabel())); + if(!ev_voxel3d) { + LARCV_CRITICAL() << "Output voxel3d could not be created!" << std::endl; + throw larbys(); + } + + // + // Loop over mctracks to select relevant MC charge deposition to make the image for + // + std::vector track_v; + for(auto const& mctrack : LArData()) { + + if(_origin && ((unsigned short)(mctrack.Origin())) != _origin) continue; + + if(mctrack.TrackID() >= track_v.size()) + track_v.resize(mctrack.TrackID()+1,0); + track_v[mctrack.TrackID()] = 1; + + if(mctrack.MotherTrackID() >= track_v.size()) + track_v.resize(mctrack.MotherTrackID()+1,0); + track_v[mctrack.MotherTrackID()] = 1; + + if(mctrack.AncestorTrackID() >= track_v.size()) + track_v.resize(mctrack.AncestorTrackID()+1,0); + track_v[mctrack.AncestorTrackID()] = 1; + } + + + for(auto const& mcshower : LArData()) { + + if(_origin && ((unsigned short)(mcshower.Origin())) != _origin) continue; + + if(mcshower.TrackID() >= track_v.size()) + track_v.resize(mcshower.TrackID()+1,0); + track_v[mcshower.TrackID()] = 1; + + if(mcshower.MotherTrackID() >= track_v.size()) + track_v.resize(mcshower.MotherTrackID()+1,0); + track_v[mcshower.MotherTrackID()] = 1; + + if(mcshower.AncestorTrackID() >= track_v.size()) + track_v.resize(mcshower.AncestorTrackID()+1,0); + track_v[mcshower.AncestorTrackID()] = 1; + + for(auto const& daughter_track_id : mcshower.DaughterTrackID()) { + if(daughter_track_id == larcv::kINVALID_UINT) + continue; + if(daughter_track_id >= track_v.size()) + track_v.resize(daughter_track_id+1,0); + track_v[daughter_track_id] = 1; + } + } + + // + // Create Meta + // + // 0) get z range from plane2's wire range + double zmin = meta_v.at(2).min_x() * supera::WirePitch(_target_plane); + double zmax = meta_v.at(2).max_x() * supera::WirePitch(_target_plane); + double ymin = -1 * supera::DetHalfHeight(); + double ymax = supera::DetHalfHeight(); + /* + std::cout<(), + TimeOffset() + supera::TriggerOffsetTPC() / supera::TPCTickPeriod(), + _target_plane); + + ev_voxel3d->Move(std::move(voxel3dset)); + + return true; + } + + void SuperaSimVoxel3D::finalize() + {} + +} +#endif diff --git a/arxiv/SuperaSimVoxel3D.h b/arxiv/SuperaSimVoxel3D.h new file mode 100644 index 0000000..1c5c2ef --- /dev/null +++ b/arxiv/SuperaSimVoxel3D.h @@ -0,0 +1,74 @@ +/** + * \file SuperaSimVoxel3D.h + * + * \ingroup Package_Name + * + * \brief Class def header for a class SuperaSimVoxel3D + * + * @author kazuhiro + */ + +/** \addtogroup Package_Name + + @{*/ +#ifndef __SUPERASIMVOXEL3D_H__ +#define __SUPERASIMVOXEL3D_H__ +#include "SuperaBase.h" +#include "FMWKInterface.h" +#include "ParamsVoxel3D.h" +#include "ImageMetaMaker.h" +#include "DataFormat/Image2D.h" + +namespace larcv { + + /** + \class ProcessBase + User defined class SuperaSimVoxel3D ... these comments are used to generate + doxygen documentation! + */ + class SuperaSimVoxel3D : public SuperaBase, + public supera::ParamsVoxel3D, + public supera::ImageMetaMaker { + + public: + + /// Default constructor + SuperaSimVoxel3D(const std::string name="SuperaSimVoxel3D"); + + /// Default destructor + ~SuperaSimVoxel3D(){} + + void configure(const PSet&); + + void initialize(); + + bool process(IOManager& mgr); + + void finalize(); + + private: + + unsigned short _origin; + double _voxel_size; + size_t _target_plane; + size_t _t0_tick; + }; + + /** + \class larcv::SuperaSimVoxel3DFactory + \brief A concrete factory class for larcv::SuperaSimVoxel3D + */ + class SuperaSimVoxel3DProcessFactory : public ProcessFactoryBase { + public: + /// ctor + SuperaSimVoxel3DProcessFactory() { ProcessFactory::get().add_factory("SuperaSimVoxel3D",this); } + /// dtor + ~SuperaSimVoxel3DProcessFactory() {} + /// creation method + ProcessBase* create(const std::string instance_name) { return new SuperaSimVoxel3D(instance_name); } + }; + +} +#endif +/** @} */ // end of doxygen group + diff --git a/example_drivers/README b/example_drivers/README new file mode 100644 index 0000000..8136d76 --- /dev/null +++ b/example_drivers/README @@ -0,0 +1,5 @@ +made by taritree. not official production fcl files. + +used as simple examples for cookbook tutorial. +https://github.com/twongjirad/LArLiteSoftCookBook/wiki/Preparing-Images + diff --git a/example_drivers/dldata_larlite_supera.fcl b/example_drivers/dldata_larlite_supera.fcl new file mode 100644 index 0000000..7d32fc7 --- /dev/null +++ b/example_drivers/dldata_larlite_supera.fcl @@ -0,0 +1,62 @@ +#include "dldata_fclbase_services.fcl" +#include "dldata_fclbase_analyzers.fcl" +#include "time_memory_tracker_microboone.fcl" + +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + supera_params: "supera_basic.fcl" + out_filename: "larcv.root" + unique_filename: false + stream: "data" +} +END_PROLOG + +process_name: LArLiteMeatSlicer + +services: +{ + scheduler: { defaultExceptions: false } +# TFileService: { fileName: "mc_hist.root" } + TimeTracker: @local::microboone_time_tracker + MemoryTracker: @local::microboone_memory_tracker + message: @local::microboone_message_services_prod_debug +# FileCatalogMetadata: @local::art_file_catalog_mc + @table::dldata_services +# LArCVMetaMaker: {Enable: true} +} + +services.TimeTracker.printSummary: true +services.TimeTracker.dbOutput: { + filename: "" + overwrite: false +} +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false + +source_reprocess: +{ + module_type: RootInput + maxEvents: 100000 # Number of events to create +} + +outputs: +{ +} + +physics: +{ + + # include this if you want to use the V-plane fix (recommended) + analyzers: { + supera: @local::SuperaModule + @table::dldata_analyzers + } + + ana: [opdigit, opreco, reco2d, supera] + + trigger_paths: [] + end_paths: [ ana ] + +} + diff --git a/example_drivers/dldata_larlite_supera_calmod.fcl b/example_drivers/dldata_larlite_supera_calmod.fcl new file mode 100644 index 0000000..b69676e --- /dev/null +++ b/example_drivers/dldata_larlite_supera_calmod.fcl @@ -0,0 +1,68 @@ +#include "dldata_fclbase_services.fcl" +#include "dldata_fclbase_analyzers.fcl" +#include "time_memory_tracker_microboone.fcl" + +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + supera_params: "supera_example_calmod.fcl" + out_filename: "larcv.root" + unique_filename: false + stream: "data" +} +VPlaneHandler: { + module_type: "VPlaneHandler" + ProducerLabel: "caldata" + Smooth: true + HandlePlateau: true + Shift: true +} +END_PROLOG + +process_name: LArLiteMeatSlicer + +services: +{ + scheduler: { defaultExceptions: false } + TimeTracker: @local::microboone_time_tracker + MemoryTracker: @local::microboone_memory_tracker + message: @local::microboone_message_services_prod_debug + @table::dldata_services +} + +services.TimeTracker.printSummary: true +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false +services.MemoryTracker.dbOutput: { + filename: "" + overwrite: false +} + +source_reprocess: +{ + module_type: RootInput + maxEvents: 100000 # Number of events to create +} + +outputs: +{ +} + +physics: +{ + + # include this if you want to use the V-plane fix (recommended) + producers: { calmod: @local::VPlaneHandler } + analyzers: { + supera: @local::SuperaModule + @table::dldata_analyzers + } + + vplanefix: [ calmod ] + ana: [opdigit, opreco, reco2d, supera] + + trigger_paths: [ vplanefix ] + end_paths: [ ana ] + +} + diff --git a/example_drivers/dlmc_bnb_nu_larlite_supera.fcl b/example_drivers/dlmc_bnb_nu_larlite_supera.fcl new file mode 100644 index 0000000..d57363b --- /dev/null +++ b/example_drivers/dlmc_bnb_nu_larlite_supera.fcl @@ -0,0 +1,125 @@ +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + supera_params: "supera_mcexample_calmod.fcl" + out_filename: "larcv.root" + unique_filename: false + stream: "mc" +} +VPlaneHandler: { + module_type: "VPlaneHandler" + ProducerLabel: "caldata" + Smooth: true + HandlePlateau: true + Shift: true +} +END_PROLOG + +#include "dlmc_fclbase_driver.fcl" + +process_name: BNBNuLArLiteSupera + +source: @local::source_gen + +services.TimeTracker.printSummary: true +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false +services.MemoryTracker.dbOutput: { + filename: "" + overwrite: false +} + + +# rebuild producers table w/ vplanehandle +physics.producers: { + @table::dlmc_producers + calmod: @local::VPlaneHandler +} + +# rebuild analyzers table w/ supera +physics.analyzers: { + @table::dlmc_analyzers + supera: @local::SuperaModule +} + +physics.planefix: [ calmod ] +physics.ana: [ @sequence::dlmc_analyze_all, supera ] +physics.sim: [ @sequence::dlmc_process_all, calmod ] +physics.end_paths: [ ana ] +physics.trigger_paths: [ sim ] + +# GENIE +physics.producers.generator: @local::microboone_genie_simple +physics.producers.generator.GlobalTimeOffset: 3125. +physics.producers.generator.RandomTimeOffset: 1600. +physics.producers.generator.TopVolume: "volTPCActive" +physics.producers.generator.BeamName: "booster" +physics.producers.generator.FluxCopyMethod: "IFDH" +physics.producers.generator.MaxFluxFileMB: 2000 + +# Filter output +physics.analyzers.mcinfo.SelectEvents: [] +physics.analyzers.simch.SelectEvents: [] +physics.analyzers.opdigit.SelectEvents: [] +physics.analyzers.opreco.SelectEvents: [] +physics.analyzers.wire.SelectEvents: [] +physics.analyzers.reco2d.SelectEvents: [] + +services.UBOpticalChConfig.PedestalSpread: [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # channels 0-35 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # logic channels 36-47 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # channels 100-135 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # logic channels 136-147 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # channels 200-236 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] # channels 300-335 + +services.UBOpticalChConfig.DarkRate: [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # channels 0-35 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # logic channels 36-47 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # channels 100-135 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # logic channels 136-147 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, # channels 200-236 + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] # channels 300-335 + diff --git a/example_drivers/project_supera_bnb_nu_foroverlay.xml b/example_drivers/project_supera_bnb_nu_foroverlay.xml new file mode 100644 index 0000000..f282d2f --- /dev/null +++ b/example_drivers/project_supera_bnb_nu_foroverlay.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + +]> + + + + + + + 1000 + + + SL6 + + + + + &release; + e14:prof + /uboone/app/users/tmw/dev/dev_dl2/larsoft.tar + + + + + /uboone/app/users/tmw/projects/meatslicer + + + + dlmc_bnb_nu_larlite_supera.fcl + &projectout;/&name;_&dl_part;/out/&release; + &projectout;/&name;_&dl_part;/log/&release; + &projectout;/&name;_&dl_part;/work/&release; + 1 + larlite + DEDICATED,OPPORTUNISTIC + --expected-lifetime=medium + + + + &file_type; + + + &run_type; + + + + diff --git a/example_drivers/project_supera_extunbiased.xml b/example_drivers/project_supera_extunbiased.xml new file mode 100644 index 0000000..2f1bbb8 --- /dev/null +++ b/example_drivers/project_supera_extunbiased.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + +]> + + + + + + + 1000 + + + SL6 + + + + + &release; + e14:prof + /uboone/app/users/tmw/dev/dev_dl2/larsoft.tar + + + + + /uboone/app/users/tmw/projects/meatslicer + + + + dldata_larlite_supera.fcl + prod_reco2_bnbunbiased_v6_mcc8 + &projectout;/&name;_&dl_part;/out/&release; + &projectout;/&name;_&dl_part;/log/&release; + &projectout;/&name;_&dl_part;/work/&release; + 1 + 10 + larlite + DEDICATED,OPPORTUNISTIC + --expected-lifetime=medium + + + + &file_type; + + + &run_type; + + + + diff --git a/example_drivers/supera_basic.fcl b/example_drivers/supera_basic.fcl new file mode 100644 index 0000000..59b33f3 --- /dev/null +++ b/example_drivers/supera_basic.fcl @@ -0,0 +1,61 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask","SuperaOpDigit"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask","SuperaOpDigit"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMask: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaOpDigit: { + Verbosity: 2 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + MetaConfig: { + MinTime: 0 + MinWire: 0 + TimeOffset: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/example_drivers/supera_basic_calmod.fcl b/example_drivers/supera_basic_calmod.fcl new file mode 100644 index 0000000..8e3ecda --- /dev/null +++ b/example_drivers/supera_basic_calmod.fcl @@ -0,0 +1,62 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask","SuperaOpDigit"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask","SuperaOpDigit"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMask: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + #LArWireProducer: "caldata" + LArWireProducer: "calmod" + TimeOffset: 2400 + } + SuperaOpDigit: { + Verbosity: 2 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + MetaConfig: { + MinTime: 0 + MinWire: 0 + TimeOffset: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/example_drivers/supera_example_calmod.fcl b/example_drivers/supera_example_calmod.fcl new file mode 100644 index 0000000..8e3ecda --- /dev/null +++ b/example_drivers/supera_example_calmod.fcl @@ -0,0 +1,62 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask","SuperaOpDigit"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask","SuperaOpDigit"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMask: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + #LArWireProducer: "caldata" + LArWireProducer: "calmod" + TimeOffset: 2400 + } + SuperaOpDigit: { + Verbosity: 2 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + MetaConfig: { + MinTime: 0 + MinWire: 0 + TimeOffset: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/example_drivers/supera_mcexample_calmod.fcl b/example_drivers/supera_mcexample_calmod.fcl new file mode 100644 index 0000000..3bebe1a --- /dev/null +++ b/example_drivers/supera_mcexample_calmod.fcl @@ -0,0 +1,111 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMask","WireMask","SuperaOpDigit"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMaskWire","WireMaskSegment","SuperaOpDigit"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMaskWire: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + WireMaskSegment: { + ChStatusProducer: "wire" + ImageProducer: "segment" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + LArWireProducer: "calmod" + TimeOffset: 2400 + } + SuperaSimCh: { + Verbosity: 2 + OutImageLabel: "segment" + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + Origin: 1 + TimeOffset: 2400 + } + SuperaMCROI: { + Verbosity: 2 + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + TimeOffset: 2400 + Origin: 0 + StoreG4SecondaryROI: false + StoreG4PrimaryROI: true + FilterTargetPDG: [] + FilterTargetInitEMin: [] + FilterTargetDepEMin: [] + ShowerInitEMin: 0 + ShowerDepEMin: 20 + TrackInitEMin: 0 + TrackDepEMin: 20 + FilterROIMinRows: 0 + FilterROIMinCols: 0 + MCParticleTree: { + Verbosity: 2 + UseG4Primary: false + DTMax: 10000 + } + MCROIMaker: { + Verbosity: 2 + MaxTimeTick: 8448 + TimePadding: 10 + WirePadding: 10 + MinWidth: 2 + MinHeight: 2 + ApplySCE: true + } + } + SuperaOpDigit: { + Verbosity: 2 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + MetaConfig: { + MinTime: 0 + MinWire: 0 + TimeOffset: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/example_drivers/supera_segment_calmod.fcl b/example_drivers/supera_segment_calmod.fcl new file mode 100644 index 0000000..3bebe1a --- /dev/null +++ b/example_drivers/supera_segment_calmod.fcl @@ -0,0 +1,111 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMask","WireMask","SuperaOpDigit"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMaskWire","WireMaskSegment","SuperaOpDigit"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMaskWire: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + WireMaskSegment: { + ChStatusProducer: "wire" + ImageProducer: "segment" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + LArWireProducer: "calmod" + TimeOffset: 2400 + } + SuperaSimCh: { + Verbosity: 2 + OutImageLabel: "segment" + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + Origin: 1 + TimeOffset: 2400 + } + SuperaMCROI: { + Verbosity: 2 + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + TimeOffset: 2400 + Origin: 0 + StoreG4SecondaryROI: false + StoreG4PrimaryROI: true + FilterTargetPDG: [] + FilterTargetInitEMin: [] + FilterTargetDepEMin: [] + ShowerInitEMin: 0 + ShowerDepEMin: 20 + TrackInitEMin: 0 + TrackDepEMin: 20 + FilterROIMinRows: 0 + FilterROIMinCols: 0 + MCParticleTree: { + Verbosity: 2 + UseG4Primary: false + DTMax: 10000 + } + MCROIMaker: { + Verbosity: 2 + MaxTimeTick: 8448 + TimePadding: 10 + WirePadding: 10 + MinWidth: 2 + MinHeight: 2 + ApplySCE: true + } + } + SuperaOpDigit: { + Verbosity: 2 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + MetaConfig: { + MinTime: 0 + MinWire: 0 + TimeOffset: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/experiments/uboone/CMakeLists.txt b/experiments/uboone/CMakeLists.txt new file mode 100644 index 0000000..05f47cf --- /dev/null +++ b/experiments/uboone/CMakeLists.txt @@ -0,0 +1,111 @@ +set( LARCV_LIB -L$ENV{LARCV_LIBDIR} -llarcv ) + +set( UBOONECODE_LIB -L$ENV{UBOONECODE_LIB} ) + +include_directories ( $ENV{LARCV_INCDIR} ) + +link_libraries( ${LIB_NAME} -L$ENV{BOOST_LIB} -lboost_system ${ROOTLIB} ${LARCV_LIB}) # All execs need this. + +#add_subdirectory(job) + +art_make( EXCLUDE LArCVMetaMaker_service.cc + BASENAME_ONLY + LIBRARY_NAME uboonecode_uboone_LArCVImageMaker + LIB_LIBRARIES + larcore_Geometry + uboone_Geometry + uboonecode_uboone_MuCS + larcore_Geometry_Geometry_service + larsim_Simulation nutools_ParticleNavigation lardataobj_Simulation + lardataobj_RecoBase + nusimdata_SimulationBase + lardataobj_MCBase + larcoreobj_SummaryData + lardataobj_RawData + lardata_RecoObjects larreco_Deprecated + ${UBOONECODE_LIB} + nusimdata_SimulationBase + ${LARRECO_LIB} + ${LARDATA_LIB} + ${ART_FRAMEWORK_CORE} + ${ART_FRAMEWORK_PRINCIPAL} + ${ART_FRAMEWORK_BASIC} + ${ART_FRAMEWORK_SERVICES_REGISTRY} + ${ART_FRAMEWORK_SERVICES_OPTIONAL} + ${ART_FRAMEWORK_SERVICES_OPTIONAL_TFILESERVICE_SERVICE} + art_Persistency_Common canvas_Persistency_Common + art_Persistency_Provenance canvas_Persistency_Provenance + art_Utilities canvas_Utilities + ${MF_MESSAGELOGGER} + ${MF_UTILITIES} + ${FHICLCPP} + ${CETLIB} + #cetlib cetlib_except + ${ROOT_GEOM} + ${ROOT_XMLIO} + ${ROOT_GDML} + ${ROOT_BASIC_LIB_LIST} + + MODULE_LIBRARIES + uboonecode_uboone_LArCVImageMaker + TFileMetadataMicroBooNE_service + FileCatalogMetadataMicroBooNE_service + LArCVMetaMaker_service + uboonecode_uboone_MuCS + larcore_Geometry + uboone_Geometry + larcore_Geometry_Geometry_service + larsim_Simulation nutools_ParticleNavigation lardataobj_Simulation + larevt_CalibrationDBI_IOVData + larevt_CalibrationDBI_Providers + nusimdata_SimulationBase + lardata_Utilities + lardataobj_MCBase + larcoreobj_SummaryData + lardataobj_RawData + lardataobj_RecoBase + lardata_RecoObjects larreco_Deprecated + larevt_Filters + larevt_CalibrationDBI_IOVData + larevt_CalibrationDBI_Providers + ${UBOONECODE_LIB} + nusimdata_SimulationBase + ${LARRECO_LIB} + ${LARDATA_LIB} + ${ART_FRAMEWORK_CORE} + ${ART_FRAMEWORK_PRINCIPAL} + ${ART_FRAMEWORK_BASIC} + ${ART_FRAMEWORK_SERVICES_REGISTRY} + ${ART_FRAMEWORK_SERVICES_OPTIONAL} + ${ART_FRAMEWORK_SERVICES_OPTIONAL_TFILESERVICE_SERVICE} + art_Persistency_Common canvas_Persistency_Common + art_Persistency_Provenance canvas_Persistency_Provenance + art_Utilities canvas_Utilities + ${MF_MESSAGELOGGER} + ${MF_UTILITIES} + ${FHICLCPP} + ${CETLIB} + #cetlib_except + ${ROOT_GEOM} + ${ROOT_XMLIO} + ${ROOT_GDML} + ${ROOT_BASIC_LIB_LIST} + ) + +simple_plugin(LArCVMetaMaker "service" + TFileMetadataMicroBooNE_service + FileCatalogMetadataMicroBooNE_service + ${ART_FRAMEWORK_SERVICES_SYSTEM_FILECATALOGMETADATA_SERVICE} + art_Utilities canvas_Utilities + ${MF_MESSAGELOGGER} + ${MF_UTILITIES} + ${FHICLCPP} + ${CETLIB} + #cetlib cetlib_except + ${ROOT_BASIC_LIB_LIST} + BASENAME_ONLY +) + +# install_headers() +install_fhicl() +install_source() diff --git a/experiments/uboone/FMWKInterface.cxx b/experiments/uboone/FMWKInterface.cxx new file mode 100644 index 0000000..48747f8 --- /dev/null +++ b/experiments/uboone/FMWKInterface.cxx @@ -0,0 +1,176 @@ +#ifndef __FMWKINTERFACE_CXX__ +#define __FMWKINTERFACE_CXX__ + +#include "art/Framework/Services/Registry/ServiceHandle.h" +#include "larcv/core/Base/larbys.h" +#include "FMWKInterface.h" +#include "lardata/DetectorInfoServices/DetectorPropertiesServiceStandard.h" +#include "lardata/DetectorInfoServices/LArPropertiesServiceStandard.h" +#include "lardata/DetectorInfoServices/DetectorClocksServiceStandard.h" +#include "larevt/SpaceChargeServices/SpaceChargeService.h" + +namespace supera { + + ::geo::WireID ChannelToWireID(unsigned int ch) + { + auto const* geom = ::lar::providerFrom(); + return geom->ChannelToWire(ch).front(); + } + + double DriftVelocity() + { + auto const* detp = ::lar::providerFrom(); + return detp->DriftVelocity(); + } + + unsigned int NumberTimeSamples() + { + throw ::larcv::larbys("NumberTimeSamples function not available!"); + auto const* detp = ::lar::providerFrom(); + return detp->NumberTimeSamples(); + } + + unsigned int Nchannels() + { + auto const* geom = ::lar::providerFrom(); + return geom->Nchannels(); + } + + unsigned int Nplanes() + { + auto const* geom = ::lar::providerFrom(); + return geom->Nplanes(); + } + + unsigned int Nwires(unsigned int plane) + { + auto const* geom = ::lar::providerFrom(); + return geom->Nwires(plane); + } + + unsigned int NearestWire(const TVector3& xyz, unsigned int plane) + { + double min_wire=0; + double max_wire=Nwires(plane)-1; + auto const* geom = ::lar::providerFrom(); + + double wire = geom->WireCoordinate(xyz[1],xyz[2],plane,0,0) + 0.5; + if(wiremax_wire) wire = max_wire; + + return (unsigned int)wire; + } + + unsigned int NearestWire(const double* xyz, unsigned int plane) + { + double min_wire=0; + double max_wire=Nwires(plane)-1; + auto const* geom = ::lar::providerFrom(); + + double wire = geom->WireCoordinate(xyz[1],xyz[2],plane,0,0) + 0.5; + if(wiremax_wire) wire = max_wire; + + return (unsigned int)wire; + } + + double WireAngleToVertical(unsigned int plane) + { + auto const* geom = ::lar::providerFrom(); + return geom->WireAngleToVertical(geo::View_t(plane)); + } + + double WirePitch(size_t plane) + { + auto const* geom = ::lar::providerFrom(); + return geom->WirePitch(0,1,plane); + } + + double DetHalfWidth() + { + auto const* geom = ::lar::providerFrom(); + return geom->DetHalfWidth(); + } + + double DetHalfHeight() + { + auto const* geom = ::lar::providerFrom(); + return geom->DetHalfHeight(); + } + + double DetLength() + { + auto const* geom = ::lar::providerFrom(); + return geom->DetLength(); + } + + int TPCG4Time2Tick(double ns) + { + auto const* ts = ::lar::providerFrom(); + return ts->TPCG4Time2Tick(ns); + } + + int TPCG4Time2TDC(double ns) + { + auto const* ts = ::lar::providerFrom(); + return ts->TPCG4Time2TDC(ns); + } + + double TPCTDC2Tick(double tdc) + { + auto const* ts = ::lar::providerFrom(); + return ts->TPCTDC2Tick(tdc); + } + + double TPCTickPeriod() + { + auto const* ts = ::lar::providerFrom(); + return ts->TPCClock().TickPeriod(); + } + + double TriggerOffsetTPC() + { + auto const* ts = ::lar::providerFrom(); + return ts->TriggerOffsetTPC(); + } + + double PlaneTickOffset(size_t plane0, size_t plane1) + { + static double pitch = ::lar::providerFrom()->PlanePitch(); + static double tick_period = ::lar::providerFrom()->TPCClock().TickPeriod(); + return (plane1 - plane0) * pitch / DriftVelocity() / tick_period; + } + + void ApplySCE(double& x, double& y, double& z) + { + auto xyz = ::lar::providerFrom()->GetPosOffsets(x,y,z); + x = x - xyz[0] + 0.7; + y = y + xyz[1]; + z = z + xyz[2]; + } + + void ApplySCE(double* xyz) + { + double x = xyz[0]; + double y = xyz[1]; + double z = xyz[2]; + ApplySCE(x,y,z); + xyz[0] = x; + xyz[1] = y; + xyz[2] = z; + } + + void ApplySCE(TVector3& xyz) + { + double x = xyz[0]; + double y = xyz[1]; + double z = xyz[2]; + ApplySCE(x,y,z); + xyz[0] = x; + xyz[1] = y; + xyz[2] = z; + } + +} + +#endif diff --git a/experiments/uboone/FMWKInterface.h b/experiments/uboone/FMWKInterface.h new file mode 100644 index 0000000..cea06f4 --- /dev/null +++ b/experiments/uboone/FMWKInterface.h @@ -0,0 +1,115 @@ +#ifndef __FMWKINTERFACE_H__ +#define __FMWKINTERFACE_H__ + +//#include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h" +#include "larcore/Geometry/Geometry.h" +#include "fhiclcpp/ParameterSet.h" +#include "larcv/core/Base/PSet.h" +#include "nusimdata/SimulationBase/MCTruth.h" +#include "lardataobj/RecoBase/Hit.h" +#include "lardataobj/RecoBase/Wire.h" +#include "lardataobj/RawData/OpDetWaveform.h" +#include "lardataobj/MCBase/MCShower.h" +#include "lardataobj/MCBase/MCTrack.h" +#include "lardataobj/Simulation/SimChannel.h" + +namespace supera { + typedef larcv::PSet Config_t; + typedef recob::Wire LArWire_t; + typedef raw::OpDetWaveform LArOpDigit_t; + typedef recob::Hit LArHit_t; + typedef simb::MCTruth LArMCTruth_t; + typedef sim::MCTrack LArMCTrack_t; + typedef sim::MCShower LArMCShower_t; + typedef sim::SimChannel LArSimCh_t; + typedef sim::MCStep LArMCStep_t; +} +// +// Utility functions (geometry, lar properties, etc.) +// +namespace supera { + + //typedef ::fhicl::ParameterSet Config_t; + + // + // LArProperties + // + + /// DriftVelocity in cm/us + double DriftVelocity(); + + // + // Geometry + // + + /// Channel number to wire ID + ::geo::WireID ChannelToWireID(unsigned int ch); + + /// Number of channels + unsigned int Nchannels(); + + /// Number of planes + unsigned int Nplanes(); + + /// Number of wires + unsigned int Nwires(unsigned int plane); + + /// Nearest wire + unsigned int NearestWire(const TVector3& xyz, unsigned int plane); + + /// Nearest wire + unsigned int NearestWire(const double* xyz, unsigned int plane); + + /// Angle from z-axis + double WireAngleToVertical(unsigned int plane); + + /// Wire pitch + double WirePitch(size_t plane); + + /// Detector height + double DetHalfHeight(); + + /// Detector width + double DetHalfWidth(); + + /// Detector length + double DetLength(); + + // + // DetectorClockService + // + + /// Number of time ticks + unsigned int NumberTimeSamples(); + + /// G4 time to TPC tick + int TPCG4Time2Tick(double ns); + + /// G4 time to TPC tick + int TPCG4Time2TDC(double ns); + + /// per-plane tick offset + double PlaneTickOffset(size_t plane0, size_t plane1); + + /// TPC TDC to Tick + double TPCTDC2Tick(double tdc); + + /// Trigger tick + double TriggerOffsetTPC(); + + /// TPC sampling period + double TPCTickPeriod(); + + // + // SpaceChargeService + // + /// Truth position to shifted + void ApplySCE(double& x, double& y, double& z); + /// Truth position to shifted + void ApplySCE(double* xyz); + /// Truth position to shifted + void ApplySCE(TVector3& xyz); + +} + +#endif diff --git a/ignore/dldata_larlite_supera_calmod.fcl b/ignore/dldata_larlite_supera_calmod.fcl new file mode 100644 index 0000000..0284f11 --- /dev/null +++ b/ignore/dldata_larlite_supera_calmod.fcl @@ -0,0 +1,81 @@ +#include "dldata_fclbase_services.fcl" +#include "dldata_fclbase_analyzers.fcl" +#include "time_memory_tracker_microboone.fcl" + +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + #supera_params: "supera_basic.fcl" + supera_params: "supera_basic.fcl" + out_filename: "larcv.root" + unique_filename: false + stream: "data" +} +VPlaneHandler: { + module_type: "VPlaneHandler" + ProducerLabel: "caldata" + Smooth: true + HandlePlateau: true + Shift: true +} +END_PROLOG + +process_name: LArLiteMeatSlicer + +services: +{ + scheduler: { defaultExceptions: false } +# TFileService: { fileName: "mc_hist.root" } + TimeTracker: @local::microboone_time_tracker + MemoryTracker: @local::microboone_memory_tracker + message: @local::microboone_message_services_prod_debug +# FileCatalogMetadata: @local::art_file_catalog_mc + @table::dldata_services +# LArCVMetaMaker: {Enable: true} +} + +services.TimeTracker.printSummary: true +services.TimeTracker.dbOutput: {} +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false +services.MemoryTracker.filename: "" + +#services.FileCatalogMetadata.applicationVersion: "develop" +#services.FileCatalogMetadata.fileType: "mc" +#services.FileCatalogMetadata.runType: "physics" +#services.FileCatalogMetadataMicroBooNE: { +# FCLName: "data_supera.fcl" +# FCLVersion: "develop" +# ProjectName: "lite" +# ProjectStage: "lite" +# ProjectVersion: "develop" +#} + +source_reprocess: +{ + module_type: RootInput + maxEvents: 100000 # Number of events to create +} + +outputs: +{ +} + +physics: +{ + + # include this if you want to use the V-plane fix (recommended) + producers: { calmod: @local::VPlaneHandler } + analyzers: { + supera: @local::SuperaModule + @table::dldata_analyzers + } + + vplanefix: [ calmod ] + ana: [opdigit, opreco, reco2d, supera] + + trigger_paths: [ vplanefix ] + end_paths: [ ana ] + +} + diff --git a/ignore/mc_segment_supera.fcl b/ignore/mc_segment_supera.fcl new file mode 100644 index 0000000..6643a03 --- /dev/null +++ b/ignore/mc_segment_supera.fcl @@ -0,0 +1,73 @@ +#include "dldata_fclbase_services.fcl" +#include "dldata_fclbase_analyzers.fcl" +#include "time_memory_tracker_microboone.fcl" + +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + supera_params: "supera_segment.fcl" + out_filename: "larcv.root" + unique_filename: false + stream: "data" +} +END_PROLOG + +process_name: LArLite + +services: +{ + scheduler: { defaultExceptions: false } + TFileService: { fileName: "mc_hist.root" } + TimeTracker: @local::microboone_time_tracker + MemoryTracker: @local::microboone_memory_tracker + message: @local::microboone_message_services_prod_debug + FileCatalogMetadata: @local::art_file_catalog_mc + @table::dldata_services + LArCVMetaMaker: {Enable: true} +} + +services.TimeTracker.printSummary: false +services.TimeTracker.dbOutput: {} +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false +services.MemoryTracker.filename: "" + +services.FileCatalogMetadata.applicationVersion: "develop" +services.FileCatalogMetadata.fileType: "mc" +services.FileCatalogMetadata.runType: "physics" +services.FileCatalogMetadataMicroBooNE: { + FCLName: "data_supera.fcl" + FCLVersion: "develop" + ProjectName: "lite" + ProjectStage: "lite" + ProjectVersion: "develop" +} + +source_reprocess: +{ + module_type: RootInput + maxEvents: 100000 # Number of events to create +} + +physics: +{ + analyzers: { + supera: @local::SuperaModule + @table::dldata_analyzers + } + ana: [opdigit, opreco, reco2d, supera] + end_paths: [ana] + trigger_paths: [] +} + +outputs: +{ + out1: + { + module_type: RootOutput + fileName: "larsoft.root" #default file name, can override from command line with -o or --output + dataTier: "postreco" + compressionLevel: 1 + } +} + diff --git a/ignore/test_supera.fcl b/ignore/test_supera.fcl new file mode 100644 index 0000000..94e1a7b --- /dev/null +++ b/ignore/test_supera.fcl @@ -0,0 +1,77 @@ +#include "dldata_fclbase_services.fcl" +#include "dldata_fclbase_analyzers.fcl" +#include "time_memory_tracker_microboone.fcl" +#include "litemc_rawdigit.fcl" + +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + supera_params: "supera_basic.fcl" + out_filename: "larcv.root" + unique_filename: false + stream: "data" +} + +VPlaneHandler: { + module_type: "VPlaneHandler" + ProducerLabel: "caldata" + Smooth: true + HandlePlateau: true + Shift: true +} +END_PROLOG + +process_name: LArLite + +services: +{ + scheduler: { defaultExceptions: false } + TFileService: { fileName: "mc_hist.root" } + TimeTracker: @local::microboone_time_tracker + MemoryTracker: @local::microboone_memory_tracker + message: @local::microboone_message_services_prod_debug + FileCatalogMetadata: @local::art_file_catalog_mc + @table::dldata_services + LArCVMetaMaker: {Enable: true} +} + +services.TimeTracker.printSummary: false +services.TimeTracker.dbOutput: {} +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false +services.MemoryTracker.filename: "" + +services.FileCatalogMetadata.applicationVersion: "develop" +services.FileCatalogMetadata.fileType: "mc" +services.FileCatalogMetadata.runType: "physics" +services.FileCatalogMetadataMicroBooNE: { + FCLName: "data_supera.fcl" + FCLVersion: "develop" + ProjectName: "lite" + ProjectStage: "lite" + ProjectVersion: "develop" +} + +source_reprocess: +{ + module_type: RootInput + maxEvents: 100000 # Number of events to create +} + +physics: +{ + producers: { calmod: @local::VPlaneHandler } + analyzers: { + supera: @local::SuperaModule + #digit: @local::litemc_rawdigit + @table::dldata_analyzers + } + #reco: [calmod] + #ana: [opdigit, opreco, reco2d, wire, supera, digit] + ana: [opdigit, opreco, reco2d, wire, supera] + end_paths: [ana] + #trigger_paths: [reco] + trigger_paths: [] +} + +physics.analyzers.digit.DataLookUpMap.rawdigit: ["wcNoiseFilter"] diff --git a/larlite/FMWKInterface.cxx b/larlite/FMWKInterface.cxx new file mode 100644 index 0000000..95acbe7 --- /dev/null +++ b/larlite/FMWKInterface.cxx @@ -0,0 +1,140 @@ +#ifndef __FMWKINTERFACE_CXX__ +#define __FMWKINTERFACE_CXX__ + +#include "FMWKInterface.h" +#include "LArUtil/InvalidWireError.h" +#include "LArUtil/DetectorProperties.h" +#include "LArUtil/LArProperties.h" +#include "LArUtil/TimeService.h" +#include "LArUtil/SpaceChargeMicroBooNE.h" + +namespace supera { + + ::larlite::geo::WireID ChannelToWireID(unsigned int ch) + { return ::larutil::Geometry::GetME()->ChannelToWireID(ch); } + + double DriftVelocity() + { return ::larutil::LArProperties::GetME()->DriftVelocity(); } + + unsigned int NumberTimeSamples() + { + // Till resolved, do not use this function + throw ::larcv::larbys("NumberTimeSamples function not available!"); + //return ::larutil::DetectorProperties::GetME()->NumberTimeSamples(); + //return 9600; + } + + double DetHalfWidth() + { return ::larutil::Geometry::GetME()->DetHalfWidth(); } + + double DetHalfHeight() + { return ::larutil::Geometry::GetME()->DetHalfHeight(); } + + double DetLength() + { return ::larutil::Geometry::GetME()->DetLength(); } + + unsigned int Nchannels() + { return ::larutil::Geometry::GetME()->Nchannels(); } + + unsigned int Nplanes() + { return ::larutil::Geometry::GetME()->Nplanes(); } + + unsigned int Nwires(unsigned int plane) + { return ::larutil::Geometry::GetME()->Nwires(plane); } + + unsigned int NearestWire(const TVector3& xyz, unsigned int plane) + { + /* + unsigned int res; + try{ + res = ::larutil::Geometry::GetME()->NearestWire(xyz,plane); + }catch( ::larutil::InvalidWireError& err){ + res = err.better_wire_number; + } + */ + double min_wire=0; + double max_wire=Nwires(plane)-1; + double wire = ::larutil::Geometry::GetME()->WireCoordinate(xyz,plane) + 0.5; + if(wiremax_wire) wire = max_wire; + + return (unsigned int)wire; + } + + unsigned int NearestWire(const double* xyz, unsigned int plane) + { + /* + unsigned int res; + try{ + res = ::larutil::Geometry::GetME()->NearestWire(xyz,plane); + }catch( ::larutil::InvalidWireError& err){ + res = err.better_wire_number; + } + */ + double min_wire=0; + double max_wire=Nwires(plane)-1; + double wire = ::larutil::Geometry::GetME()->WireCoordinate(xyz,plane) + 0.5; + if(wiremax_wire) wire = max_wire; + + return (unsigned int)wire; + } + + double PlaneTickOffset(size_t plane0, size_t plane1) + { + static double pitch = ::larutil::Geometry::GetME()->PlanePitch(); + static double tick_period = ::larutil::TimeService::GetME()->TPCClock().TickPeriod(); + return (plane1 - plane0) * pitch / DriftVelocity() / tick_period; + } + + double WirePitch(size_t plane) + { return ::larutil::Geometry::GetME()->WirePitch(::larlite::geo::View_t(plane)); } + + double WireAngleToVertical(unsigned int plane) + { return ::larutil::Geometry::GetME()->WireAngleToVertical(larlite::geo::View_t(plane)); } + + int TPCG4Time2Tick(double ns) + { return ::larutil::TimeService::GetME()->TPCG4Time2Tick(ns); } + + int TPCG4Time2TDC(double ns) + { return ::larutil::TimeService::GetME()->TPCG4Time2TDC(ns); } + + double TPCTDC2Tick(double tdc) + { return ::larutil::TimeService::GetME()->TPCTDC2Tick(tdc); } + + double TriggerOffsetTPC() + { return ::larutil::TimeService::GetME()->TriggerOffsetTPC(); } + + double TPCTickPeriod() + { return ::larutil::TimeService::GetME()->TPCClock().TickPeriod(); } + + void ApplySCE(double& x, double& y, double& z) + { + static larutil::SpaceChargeMicroBooNE sce; + auto pos = sce.GetPosOffsets(x,y,z); + x = x - pos[0] + 0.7; + y = y + pos[1]; + z = z + pos[2]; + } + + void ApplySCE(double* xyz) + { + static larutil::SpaceChargeMicroBooNE sce; + auto pos = sce.GetPosOffsets(xyz[0],xyz[1],xyz[2]); + xyz[0] = xyz[0] - pos[0] + 0.7; + xyz[1] = xyz[1] + pos[1]; + xyz[2] = xyz[2] + pos[2]; + } + + void ApplySCE(TVector3& xyz) + { + static larutil::SpaceChargeMicroBooNE sce; + auto pos = sce.GetPosOffsets(xyz[0],xyz[1],xyz[2]); + xyz[0] = xyz[0] - pos[0] + 0.7; + xyz[1] = xyz[1] + pos[1]; + xyz[2] = xyz[2] + pos[2]; + } + +} + +#endif diff --git a/larlite/FMWKInterface.h b/larlite/FMWKInterface.h new file mode 100644 index 0000000..1101edc --- /dev/null +++ b/larlite/FMWKInterface.h @@ -0,0 +1,123 @@ +#ifndef __SUPERA_FMWKINTERFACE_H__ +#define __SUPERA_FMWKINTERFACE_H__ +//#ifndef __CINT__ +//#ifndef __CLING__ + +#include "Base/PSet.h" +#include "DataFormat/mctruth.h" +#include "DataFormat/mctrack.h" +#include "DataFormat/mcshower.h" +#include "DataFormat/simch.h" +#include "DataFormat/wire.h" +#include "DataFormat/hit.h" +#include "DataFormat/ophit.h" +#include "DataFormat/opflash.h" +#include "DataFormat/opdetwaveform.h" + +// +// Data types +// +namespace supera { + + typedef ::larcv::PSet Config_t; + + typedef ::larlite::wire LArWire_t; + typedef ::larlite::opdetwaveform LArOpDigit_t; + typedef ::larlite::hit LArHit_t; + typedef ::larlite::mctruth LArMCTruth_t; + typedef ::larlite::mctrack LArMCTrack_t; + typedef ::larlite::mcshower LArMCShower_t; + typedef ::larlite::simch LArSimCh_t; + typedef ::larlite::mcstep LArMCStep_t; +} + +// +// Utility functions (geometry, lar properties, etc.) +// +#include "LArUtil/Geometry.h" +namespace supera { + + // + // LArProperties + // + + /// DriftVelocity in cm/us + double DriftVelocity(); + + // + // Geometry + // + + /// Channel number to wire ID + ::larlite::geo::WireID ChannelToWireID(unsigned int ch); + + /// Number of channels + unsigned int Nchannels(); + + /// Number of planes + unsigned int Nplanes(); + + /// Number of wires + unsigned int Nwires(unsigned int plane); + + /// Nearest wire + unsigned int NearestWire(const TVector3& xyz, unsigned int plane); + + /// Nearest wire + unsigned int NearestWire(const double* xyz, unsigned int plane); + + /// Angle from z-axis + double WireAngleToVertical(unsigned int plane); + + /// Wire pitch + double WirePitch(size_t plane); + + /// Detector height + double DetHalfHeight(); + + /// Detector width + double DetHalfWidth(); + + /// Detector length + double DetLength(); + + // + // DetectorClockService + // + + /// Number of time ticks + unsigned int NumberTimeSamples(); + + /// G4 time to TPC tick (plane 0) + int TPCG4Time2Tick(double ns); + + /// G4 time to TPC tick (plane 0) + int TPCG4Time2TDC(double ns); + + /// Tick offset for drift electrons across planes + double PlaneTickOffset(size_t plane0, size_t plane1); + + /// TDC to TPC tick + double TPCTDC2Tick(double tdc); + + /// Trigger tick + double TriggerOffsetTPC(); + + /// TPC sampling period + double TPCTickPeriod(); + + // + // SpaceChargeService + // + + /// Truth position to shifted + void ApplySCE(double& x, double& y, double& z); + /// Truth position to shifted + void ApplySCE(double* xyz); + /// Truth position to shifted + void ApplySCE(TVector3& xyz); + +} +#endif +//#endif +//#endif diff --git a/larlite/GNUmakefile b/larlite/GNUmakefile new file mode 100644 index 0000000..8c2af6c --- /dev/null +++ b/larlite/GNUmakefile @@ -0,0 +1,30 @@ +# +# This is an example GNUmakefile for my packages +# +PACKAGE_NAME = MeatSlicer + +# specific names for this package +SOURCES = $(wildcard *.cxx) +FMWK_HEADERS = LinkDef.h +HEADERS = $(filter-out $(FMWK_HEADERS), $(wildcard *.h)) +IMPS = $(wildcard *.inl) + +# include options for this package +INCFLAGS = -I. #Include itself +INCFLAGS += $(shell larcv-config --includes) +INCFLAGS += $(shell larlite-config --includes) + +# platform-specific options +OSNAME = $(shell uname -s) +HOST = $(shell uname -n) +OSNAMEMODE = $(OSNAME) + +include $(LARCV_BASEDIR)/Makefile/Makefile.${OSNAME} + +LDFLAGS += $(shell larcv-config --libs) +LDFLAGS += $(shell larlite-config --libs) +# call the common GNUmakefile +include $(LARCV_BASEDIR)/Makefile/GNUmakefile.CORE + +pkg_build: # nothing extra for this package +pkg_clean: # nothing extra for this package diff --git a/larlite/LArLiteSuperaDriver.cxx b/larlite/LArLiteSuperaDriver.cxx new file mode 100644 index 0000000..46e2332 --- /dev/null +++ b/larlite/LArLiteSuperaDriver.cxx @@ -0,0 +1,143 @@ +#ifndef LARLITE_LARLITESUPERADRIVER_CXX +#define LARLITE_LARLITESUPERADRIVER_CXX + +#include "LArLiteSuperaDriver.h" +#include "DataFormat/hit.h" +#include "DataFormat/wire.h" +#include "DataFormat/opdetwaveform.h" +#include "DataFormat/mctruth.h" +#include "DataFormat/mctrack.h" +#include "DataFormat/mcshower.h" +#include "DataFormat/simch.h" +#include "DataFormat/chstatus.h" +namespace larlite { + + bool LArLiteSuperaDriver::initialize() { + + _supera.initialize(); + return true; + } + + bool LArLiteSuperaDriver::analyze(storage_manager* storage) { + + // + // set data pointers + // + + // hit + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArHit_t)) { + if(label.empty()) continue; + print(msg::kINFO,Form("Retrieving hit data by %s",label.c_str())); + auto ev_data = storage->get_data(label); + if(!ev_data) { + std::cerr << "Could not find data by producer " << label << std::endl; + throw DataFormatException(); + } + _supera.SetDataPointer(*ev_data,label); + } + + // wire + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArWire_t)) { + if(label.empty()) continue; + print(msg::kINFO,Form("Retrieving wire data by %s",label.c_str())); + auto ev_data = storage->get_data(label); + if(!ev_data) { + std::cerr << "Could not find data by producer " << label << std::endl; + throw DataFormatException(); + } + _supera.SetDataPointer(*ev_data,label); + } + + // opdigit + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArOpDigit_t)) { + if(label.empty()) continue; + print(msg::kINFO,Form("Retrieving opdigit data by %s",label.c_str())); + auto ev_data = storage->get_data(label); + if(!ev_data) { + std::cerr << "Could not find data by producer " << label << std::endl; + throw DataFormatException(); + } + _supera.SetDataPointer(*ev_data,label); + } + + // mctruth + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArMCTruth_t)) { + if(label.empty()) continue; + print(msg::kINFO,Form("Retrieving mctruth data by %s",label.c_str())); + auto ev_data = storage->get_data(label); + if(!ev_data) { + std::cerr << "Could not find data by producer " << label << std::endl; + throw DataFormatException(); + } + _supera.SetDataPointer(*ev_data,label); + } + + // mctrack + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArMCTrack_t)) { + if(label.empty()) continue; + print(msg::kINFO,Form("Retrieving mctrack data by %s",label.c_str())); + auto ev_data = storage->get_data(label); + if(!ev_data) { + std::cerr << "Could not find data by producer " << label << std::endl; + throw DataFormatException(); + } + _supera.SetDataPointer(*ev_data,label); + } + + // mcshower + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArMCShower_t)) { + if(label.empty()) continue; + print(msg::kINFO,Form("Retrieving mcshower data by %s",label.c_str())); + auto ev_data = storage->get_data(label); + if(!ev_data) { + std::cerr << "Could not find data by producer " << label << std::endl; + throw DataFormatException(); + } + _supera.SetDataPointer(*ev_data,label); + } + + // simch + for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArSimCh_t)) { + if(label.empty()) continue; + print(msg::kINFO,Form("Retrieving simch data by %s",label.c_str())); + auto ev_data = storage->get_data(label); + if(!ev_data) { + std::cerr << "Could not find data by producer " << label << std::endl; + throw DataFormatException(); + } + _supera.SetDataPointer(*ev_data,label); + } + + // chstatus + auto supera_chstatus = _supera.SuperaChStatusPointer(); + if(supera_chstatus) { + auto ev_data = storage->get_data(supera_chstatus->InputLabel()); + if(!ev_data) { + std::cerr << "Could not find data by producer " << supera_chstatus->InputLabel() << std::endl; + throw DataFormatException(); + } + + for(auto const& chs : *ev_data) { + auto const& pid = chs.plane(); + auto const& status_v = chs.status(); + for(size_t wire=0; wireset_chstatus(pid.Plane,wire,status_v[wire]); + } + } + + // + // execute supera + // + _supera.process(storage->run_id(), storage->subrun_id(), storage->event_id()); + + return true; + } + + bool LArLiteSuperaDriver::finalize() { + + _supera.finalize(); + return true; + } + +} +#endif diff --git a/larlite/LArLiteSuperaDriver.h b/larlite/LArLiteSuperaDriver.h new file mode 100644 index 0000000..d93c9fc --- /dev/null +++ b/larlite/LArLiteSuperaDriver.h @@ -0,0 +1,68 @@ +/** + * \file LArLiteSuperaDriver.h + * + * \ingroup MeatSlicer + * + * \brief Class def header for a class LArLiteSuperaDriver + * + * @author kazuhiro + */ + +/** \addtogroup MeatSlicer + + @{*/ + +#ifndef LARLITE_LARLITESUPERADRIVER_H +#define LARLITE_LARLITESUPERADRIVER_H + +#include "Analysis/ana_base.h" +#include "LArCVSuperaDriver.h" +namespace larlite { + /** + \class LArLiteSuperaDriver + User custom analysis class made by SHELL_USER_NAME + */ + class LArLiteSuperaDriver : public ana_base{ + + public: + + /// Default constructor + LArLiteSuperaDriver(){ _name="LArLiteSuperaDriver"; _fout=0;} + + /// Default destructor + virtual ~LArLiteSuperaDriver(){} + + /** IMPLEMENT in LArLiteSuperaDriver.cc! + Initialization method to be called before the analysis event loop. + */ + virtual bool initialize(); + + /** IMPLEMENT in LArLiteSuperaDriver.cc! + Analyze a data event-by-event + */ + virtual bool analyze(storage_manager* storage); + + /** IMPLEMENT in LArLiteSuperaDriver.cc! + Finalize method to be called after all events processed. + */ + virtual bool finalize(); + + larcv::LArCVSuperaDriver& CoreDriver() { return _supera; } + + protected: + + ::larcv::LArCVSuperaDriver _supera; + + }; +} +#endif + +//************************************************************************** +// +// For Analysis framework documentation, read Manual.pdf here: +// +// http://microboone-docdb.fnal.gov:8080/cgi-bin/ShowDocument?docid=3183 +// +//************************************************************************** + +/** @} */ // end of doxygen group diff --git a/mc_segment_supera.fcl b/mc_segment_supera.fcl new file mode 100644 index 0000000..1326ad8 --- /dev/null +++ b/mc_segment_supera.fcl @@ -0,0 +1,73 @@ +#include "dldata_fclbase_services.fcl" +#include "dldata_fclbase_analyzers.fcl" +#include "time_memory_tracker_microboone.fcl" + +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + supera_params: "supera_segment.fcl" + out_filename: "larcv.root" + unique_filename: true + stream: "data" +} +END_PROLOG + +process_name: LArLite + +services: +{ + scheduler: { defaultExceptions: false } + TFileService: { fileName: "mc_hist.root" } + TimeTracker: @local::microboone_time_tracker + MemoryTracker: @local::microboone_memory_tracker + message: @local::microboone_message_services_prod_debug + FileCatalogMetadata: @local::art_file_catalog_mc + @table::dldata_services + LArCVMetaMaker: {Enable: true} +} + +services.TimeTracker.printSummary: false +services.TimeTracker.dbOutput: {} +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false +services.MemoryTracker.filename: "" + +services.FileCatalogMetadata.applicationVersion: "develop" +services.FileCatalogMetadata.fileType: "mc" +services.FileCatalogMetadata.runType: "physics" +services.FileCatalogMetadataMicroBooNE: { + FCLName: "data_supera.fcl" + FCLVersion: "develop" + ProjectName: "lite" + ProjectStage: "lite" + ProjectVersion: "develop" +} + +source_reprocess: +{ + module_type: RootInput + maxEvents: 100000 # Number of events to create +} + +physics: +{ + analyzers: { + supera: @local::SuperaModule + @table::dldata_analyzers + } + ana: [opdigit, opreco, reco2d, supera] + end_paths: [ana] + trigger_paths: [] +} + +outputs: +{ + out1: + { + module_type: RootOutput + fileName: "larsoft.root" #default file name, can override from command line with -o or --output + dataTier: "postreco" + compressionLevel: 1 + } +} + diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..78a0f07 --- /dev/null +++ b/setup.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# clean up previously set env +if [[ -z $FORCE_SUPERA_DIR ]]; then + where="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + SUPERA_DIR=${where} +else + SUPERA_DIR=$FORCE_SUPERA_DIR +fi + +experiment=$1 +if [ ! -d "$SUPERA_DIR/experiments/$experiment" ]; then + echo "Could not locate $experiment directory... make sure that exists under experiments dir" +else + export SUPERADIR=$SUPERA_DIR; + ln -sf $SUPERA_DIR/experiments/$experiment/FMWKInterface.* $SUPERA_DIR; + ln -sf $SUPERA_DIR/experiments/$experiment/CMakeLists.txt $SUPERA_DIR; +fi + + diff --git a/supera.py b/supera.py new file mode 100755 index 0000000..4285e9d --- /dev/null +++ b/supera.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +import sys,os + +if len(sys.argv) < 3: + msg = '\n' + msg += "Usage 1: %s CONFIG_FILE OUT_FILENAME $INPUT_ROOT_FILE(s)\n" % sys.argv[0] + msg += '\n' + sys.stderr.write(msg) + sys.exit(1) +#import ROOT +#from ROOT import larlite as fmwk +##from larlite import larlite as fmwk +import ROOT +from larlite import larlite as fmwk +fmwk.storage_manager +from larcv import larcv + +LL_OUTFILE='larlite_supera_out.root' +LC_OUTFILE='larcv_supera_out.root' + +if os.path.exists(LL_OUTFILE) or os.path.exists(LC_OUTFILE): + print "Output file exists. Please remove:",LL_OUTFILE,LC_OUTFILE + print "Giving up." + sys.exit(1) + +# Create ana_processor instance +my_proc = fmwk.ana_processor() + +my_proc.enable_filter(True) + +# Set input root file +for argv in sys.argv: + if argv.endswith('.root'): + my_proc.add_input_file(argv) + +# Specify IO mode +my_proc.set_io_mode(fmwk.storage_manager.kREAD) + +#my_proc.set_output_file(LL_OUTFILE) + +# Specify output root file name +my_proc.set_ana_output_file("") + +# Attach an analysis unit ... here we use a base class which does nothing. +# Replace with your analysis unit if you wish. +unit = fmwk.LArLiteSuperaDriver() +unit.CoreDriver().configure(sys.argv[1]) +unit.CoreDriver().override_output_file(LC_OUTFILE) +#unit.CoreDriver().initialize() +#unit.CoreDriver().finalize() +my_proc.add_process(unit) +#my_proc.enable_filter() + +print +print "Finished configuring ana_processor. Start event loop!" +print + +# Let's run it. +my_proc.run(0,5) + +# done! +print +print "Finished running ana_processor event loop!" +print + +sys.exit(0) diff --git a/supera_basic.fcl b/supera_basic.fcl new file mode 100644 index 0000000..6961a67 --- /dev/null +++ b/supera_basic.fcl @@ -0,0 +1,61 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaOpDigit","SuperaChStatus","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaOpDigit","SuperaChStatus","WireMask"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMask: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaOpDigit: { + Verbosity: 0 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + TimeOffset: 0 + MetaConfig: { + MinTime: 0 + MinWire: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/supera_basic_calmod.fcl b/supera_basic_calmod.fcl new file mode 100644 index 0000000..054d124 --- /dev/null +++ b/supera_basic_calmod.fcl @@ -0,0 +1,61 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaOpDigit","SuperaChStatus","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaOpDigit","SuperaChStatus","WireMask"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMask: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + LArWireProducer: "calmod" + TimeOffset: 2400 + } + SuperaOpDigit: { + Verbosity: 0 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + TimeOffset: 0 + MetaConfig: { + MinTime: 0 + MinWire: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/supera_basic_focused.fcl b/supera_basic_focused.fcl new file mode 100644 index 0000000..95aa43c --- /dev/null +++ b/supera_basic_focused.fcl @@ -0,0 +1,72 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaOpDigit","SuperaChStatus","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaOpDigit","SuperaChStatus","WireMask"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + LArSimChProducer: "" + LArMCTruthProducer: "" + PulledPork: { + Verbosity: 1 + Origin: 0 + WidthArray: [171.16552,88.681001347526518,153.6] + MinCoordinate: [-44.,-116.5,0.] + MaxCoordinate: [312.,116.5,1036.8] + Padding: [100,0,100] + TimePixels: 3072 + WirePixels: [512,512,512] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + ApplySCE: true + T0G4ns: 0 + ConstraintX: [] + ConstraintY: [] + ConstraintZ: [] + } + } + WireMask: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaOpDigit: { + Verbosity: 0 + OutImageLabel: "pmt" + LArOpDigitProducer: "saturation OpdetBeamHighGain" + TimeOffset: 0 + MetaConfig: { + MinTime: 0 + MinWire: 0 + EventImageRows: [1500] + EventImageCols: [32] + EventCompRows: [1] + EventCompCols: [1] + } + } + } +} + diff --git a/supera_michel_focused.fcl b/supera_michel_focused.fcl new file mode 100644 index 0000000..83db756 --- /dev/null +++ b/supera_michel_focused.fcl @@ -0,0 +1,58 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaChStatus","WireMask"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + LArSimChProducer: "largeant" + LArMCTruthProducer: "generator" + PulledPork: { + Verbosity: 1 + Origin: 2 + WidthArray: [171.16552,88.681001347526518,153.6] + MinCoordinate: [0.,-116.5,0.] + MaxCoordinate: [256.35,116.5,1036.8] + Padding: [10,10,10] + TimePixels: 3072 + WirePixels: [512,512,512] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + ApplySCE: true + T0G4ns: 0 + ConstraintX: [] + ConstraintY: [] + ConstraintZ: [] + } + } + WireMask: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 1 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + } +} + diff --git a/supera_michel_mc_focused.fcl b/supera_michel_mc_focused.fcl new file mode 100644 index 0000000..02a431c --- /dev/null +++ b/supera_michel_mc_focused.fcl @@ -0,0 +1,73 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","WireMask","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","WireMaskWire","WireMaskSegment"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + LArSimChProducer: "largeant" + LArMCTruthProducer: "generator" + PulledPork: { + Verbosity: 1 + Origin: 2 + WidthArray: [171.16552,88.681001347526518,153.6] + MinCoordinate: [0.,-116.5,0.] + MaxCoordinate: [256.35,116.5,1036.8] + Padding: [10,10,10] + TimePixels: 3072 + WirePixels: [512,512,512] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + ApplySCE: true + T0G4ns: 0 + ConstraintX: [] + ConstraintY: [] + ConstraintZ: [] + } + } + WireMaskWire: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + WireMaskSegment: { + ChStatusProducer: "wire" + ImageProducer: "segment" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 1 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaSimCh: { + Verbosity: 2 + OutImageLabel: "segment" + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + Origin: 0 + TimeOffset: 2400 + } + } +} + diff --git a/supera_segment.fcl b/supera_segment.fcl new file mode 100644 index 0000000..88cd856 --- /dev/null +++ b/supera_segment.fcl @@ -0,0 +1,104 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMask","WireMask","MaskImage"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMaskWire","WireMaskSegment","MaskSegment"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + } + WireMaskWire: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + WireMaskSegment: { + ChStatusProducer: "wire" + ImageProducer: "segment" + } + MaskSegment: { + Verbosity: 2 + MinPIThreshold: 2 + MaskValue: 0 + ReferenceProducer: "wire" + TargetProducer: "segment" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 2 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaSimCh: { + Verbosity: 2 + OutImageLabel: "segment" + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + Origin: 1 + TimeOffset: 2400 + } + SuperaMCROI: { + Verbosity: 2 + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + TimeOffset: 2400 + Origin: 0 + StoreG4SecondaryROI: false + StoreG4PrimaryROI: true + FilterTargetPDG: [] + FilterTargetInitEMin: [] + FilterTargetDepEMin: [] + ShowerInitEMin: 0 + ShowerDepEMin: 20 + TrackInitEMin: 0 + TrackDepEMin: 20 + FilterROIMinRows: 0 + FilterROIMinCols: 0 + MCParticleTree: { + Verbosity: 2 + UseG4Primary: false + DTMax: 10000 + } + MCROIMaker: { + Verbosity: 2 + MaxTimeTick: 8448 + TimePadding: 10 + WirePadding: 10 + MinWidth: 2 + MinHeight: 2 + ApplySCE: true + } + } + } +} + diff --git a/supera_segment_focused.fcl b/supera_segment_focused.fcl new file mode 100644 index 0000000..4709d0b --- /dev/null +++ b/supera_segment_focused.fcl @@ -0,0 +1,116 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMask","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","WireMaskWire","WireMaskSegment"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + LArSimChProducer: "largeant" + LArMCTruthProducer: "generator" + PulledPork: { + Verbosity: 1 + Origin: 0 + WidthArray: [171.16552,88.681001347526518,153.6] + MinCoordinate: [0.,-116.5,0.] + MaxCoordinate: [256.35,116.5,1036.8] + Padding: [10,10,10] + TimePixels: 3072 + WirePixels: [512,512,512] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + ApplySCE: true + T0G4ns: 0 + ConstraintX: [] + ConstraintY: [] + ConstraintZ: [] + } + } + WireMaskWire: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + WireMaskSegment: { + ChStatusProducer: "wire" + ImageProducer: "segment" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 1 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaSimCh: { + Verbosity: 2 + OutImageLabel: "segment" + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + Origin: 0 + TimeOffset: 2400 + } + SuperaMCROI: { + Verbosity: 1 + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + TimeOffset: 2400 + Origin: 0 + StoreG4SecondaryROI: false + StoreG4PrimaryROI: true + FilterTargetPDG: [] + FilterTargetInitEMin: [] + FilterTargetDepEMin: [] + ShowerInitEMin: 0 + ShowerDepEMin: 10 + TrackInitEMin: 0 + TrackDepEMin: 10 + FilterROIMinRows: 0 + FilterROIMinCols: 0 + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + MCParticleTree: { + Verbosity: 2 + UseG4Primary: true + DTMax: 10000 + } + MCROIMaker: { + Verbosity: 1 + MaxTimeTick: 8448 + TimePadding: 10 + WirePadding: 10 + MinWidth: 2 + MinHeight: 2 + ApplySCE: true + } + } + } +} + diff --git a/supera_segment_focused_plus.fcl b/supera_segment_focused_plus.fcl new file mode 100644 index 0000000..bfe9ef8 --- /dev/null +++ b/supera_segment_focused_plus.fcl @@ -0,0 +1,198 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","SuperaMCPCluster","SuperaKeyPointCluster","ImageFromPixel2D","ImageFromPixel2D","WireMask","WireMask","WireMask","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","SuperaMCPCluster","SuperaKeyPointCluster","ImagePCluster","ImageKeyPointCluster","WireMaskWire","WireMaskSegment","WireMaskISeg","WireMaskKeyPoint"] + #ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","SuperaKeyPointCluster","WireMask","WireMask"] + #ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","SuperaKeyPointCluster","WireMaskWire","WireMaskSegment"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + LArSimChProducer: "largeant" + LArMCTruthProducer: "generator" + PulledPork: { + Verbosity: 1 + Origin: 0 + WidthArray: [171.16552,88.681001347526518,153.6] + MinCoordinate: [0.,-116.5,0.] + MaxCoordinate: [256.35,116.5,1036.8] + Padding: [10,10,10] + TimePixels: 3072 + WirePixels: [512,512,512] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + ApplySCE: true + T0G4ns: 0 + ConstraintX: [] + ConstraintY: [] + ConstraintZ: [] + } + } + WireMaskWire: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + WireMaskSegment: { + ChStatusProducer: "wire" + ImageProducer: "segment" + } + WireMaskISeg: { + ChStatusProducer: "wire" + ImageProducer: "iseg" + } + WireMaskKeyPoint: { + ChStatusProducer: "wire" + ImageProducer: "keypt" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 1 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaSimCh: { + Verbosity: 2 + OutImageLabel: "segment" + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + Origin: 0 + TimeOffset: 2400 + } + SuperaKeyPointCluster: { + Verbosity: 2 + OutPixel2DLabel: "keypt" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + TimeOffset: 2400 + InputROILabel: "iseg" + ApplySCE: true + RowPad: 4 + ColPad: 4 + UsePrimaryStart: true + UseSecondaryStart: true + UseScattering: false + } + SuperaMCROI: { + Verbosity: 0 + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + TimeOffset: 2400 + Origin: 0 + StoreG4SecondaryROI: false + StoreG4PrimaryROI: true + FilterTargetPDG: [] + FilterTargetInitEMin: [] + FilterTargetDepEMin: [] + ShowerInitEMin: 0 + ShowerDepEMin: 10 + TrackInitEMin: 0 + TrackDepEMin: 10 + FilterROIMinRows: 0 + FilterROIMinCols: 0 + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + MCParticleTree: { + Verbosity: 2 + UseG4Primary: false + DTMax: 10000 + } + MCROIMaker: { + Verbosity: 1 + MaxTimeTick: 8448 + TimePadding: 10 + WirePadding: 10 + MinWidth: 2 + MinHeight: 2 + ApplySCE: true + } + } + SuperaMCPCluster: { + Verbosity: 2 + OutROILabel: "iseg" + OutPixel2DLabel: "iseg" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + + Origin: 0 + StoreG4PrimaryROI: true + StoreG4SecondaryROI: true + FilterTargetPDG: [] + FilterTargetInitEMin: [] + FilterTargetDepEMin: [] + ShowerInitEMin: 0 + ShowerDepEMin: 10 + TrackInitEMin: 0 + TrackDepEMin: 10 + FilterROIMinRows: 0 + FilterROIMinCols: 0 + + TimeOffset: 2400 +# MetaConfig: { +# MinTime: 2400 +# MinWire: 0 +# EventImageRows: [1008,1008,1008] +# EventImageCols: [3456,3456,3456] +# EventCompRows: [6,6,6] +# EventCompCols: [1,1,1] +# } + MCParticleTree: { + Verbosity: 2 + UseG4Primary: false + DTMax: 10000 + } + MCROIMaker: { + Verbosity: 1 + MaxTimeTick: 8448 + TimePadding: 10 + WirePadding: 10 + MinWidth: 2 + MinHeight: 2 + ApplySCE: true + } + } + ImagePCluster: { + PixelProducer: "iseg" + ImageProducer: "wire" + OutputProducer: "iseg" + PIType: 2 + } + ImageKeyPointCluster: { + PixelProducer: "keypt" + ImageProducer: "wire" + OutputProducer: "keypt" + PIType: 2 + } + } +} + diff --git a/supera_segment_pork3d.fcl b/supera_segment_pork3d.fcl new file mode 100644 index 0000000..31d50ea --- /dev/null +++ b/supera_segment_pork3d.fcl @@ -0,0 +1,128 @@ +ProcessDriver: { + + Verbosity: 2 + EnableFilter: false + RandomAccess: false + ProcessType: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","SuperaSimVoxel3D","WireMask","WireMask"] + ProcessName: ["SuperaMetaMaker","SuperaWire","SuperaSimCh","SuperaChStatus","SuperaMCROI","SuperaSimVoxel3D","WireMaskWire","WireMaskSegment"] + + IOManager: { + Verbosity: 2 + Name: "IOManager" + IOMode: 1 + OutFileName: "out_test.root" + InputFiles: [] + InputDirs: [] + StoreOnlyType: [] + StoreOnlyName: [] + } + + ProcessList: { + SuperaMetaMaker: { + LArSimChProducer: "largeant" + LArMCTruthProducer: "generator" + Origin: 0 + PulledPork: { + Verbosity: 1 + Origin: 0 + WidthArray: [171.16552,88.681001347526518,153.6] + TimePixels: 3072 + WirePixels: [512,512,512] + MinCoordinate: [0.,-116.5,0.] + MaxCoordinate: [256.35,116.5,1036.8] + Padding: [10,10,10] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + ApplySCE: true + T0G4ns: 0 + ConstraintX: [] + ConstraintY: [] + ConstraintZ: [] + } + } + WireMaskWire: { + ChStatusProducer: "wire" + ImageProducer: "wire" + } + WireMaskSegment: { + ChStatusProducer: "wire" + ImageProducer: "segment" + } + SuperaChStatus: { + LArChStatusProducer: "chstatus" + OutChStatusLabel: "wire" + } + SuperaWire: { + Verbosity: 1 + OutImageLabel: "wire" + LArWireProducer: "caldata" + TimeOffset: 2400 + } + SuperaSimCh: { + Verbosity: 2 + OutImageLabel: "segment" + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + Origin: 0 + TimeOffset: 2400 + } + SuperaSimVoxel3D: { + Verbosity: 0 + OutVoxel3DLabel: "simvoxel" + OutROILabel: "" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + TimeOffset: 0 + Origin: 0 + } + SuperaMCROI: { + Verbosity: 1 + OutROILabel: "segment" + LArMCTruthProducer: "generator" + LArMCTrackProducer: "mcreco" + LArMCShowerProducer: "mcreco" + LArSimChProducer: "largeant" + TimeOffset: 2400 + Origin: 0 + StoreG4SecondaryROI: false + StoreG4PrimaryROI: true + FilterTargetPDG: [] + FilterTargetInitEMin: [] + FilterTargetDepEMin: [] + ShowerInitEMin: 0 + ShowerDepEMin: 20 + TrackInitEMin: 0 + TrackDepEMin: 20 + FilterROIMinRows: 0 + FilterROIMinCols: 0 + MetaConfig: { + MinTime: 2400 + MinWire: 0 + EventImageRows: [1008,1008,1008] + EventImageCols: [3456,3456,3456] + EventCompRows: [6,6,6] + EventCompCols: [1,1,1] + } + MCParticleTree: { + Verbosity: 2 + UseG4Primary: true + DTMax: 10000 + } + MCROIMaker: { + Verbosity: 1 + MaxTimeTick: 8448 + TimePadding: 10 + WirePadding: 10 + MinWidth: 2 + MinHeight: 2 + ApplySCE: true + } + } + } +} + diff --git a/test_supera.fcl b/test_supera.fcl new file mode 100644 index 0000000..4350bb7 --- /dev/null +++ b/test_supera.fcl @@ -0,0 +1,77 @@ +#include "dldata_fclbase_services.fcl" +#include "dldata_fclbase_analyzers.fcl" +#include "time_memory_tracker_microboone.fcl" +#include "litemc_rawdigit.fcl" + +BEGIN_PROLOG +SuperaModule: { + module_type: "LArSoftSuperaSriver" + supera_params: "supera_basic.fcl" + out_filename: "larcv.root" + unique_filename: true + stream: "data" +} + +VPlaneHandler: { + module_type: "VPlaneHandler" + ProducerLabel: "caldata" + Smooth: true + HandlePlateau: true + Shift: true +} +END_PROLOG + +process_name: LArLite + +services: +{ + scheduler: { defaultExceptions: false } + TFileService: { fileName: "mc_hist.root" } + TimeTracker: @local::microboone_time_tracker + MemoryTracker: @local::microboone_memory_tracker + message: @local::microboone_message_services_prod_debug + FileCatalogMetadata: @local::art_file_catalog_mc + @table::dldata_services + LArCVMetaMaker: {Enable: true} +} + +services.TimeTracker.printSummary: false +services.TimeTracker.dbOutput: {} +services.MemoryTracker.printSummaries: [] +services.MemoryTracker.includeMallocInfo: false +services.MemoryTracker.filename: "" + +services.FileCatalogMetadata.applicationVersion: "develop" +services.FileCatalogMetadata.fileType: "mc" +services.FileCatalogMetadata.runType: "physics" +services.FileCatalogMetadataMicroBooNE: { + FCLName: "data_supera.fcl" + FCLVersion: "develop" + ProjectName: "lite" + ProjectStage: "lite" + ProjectVersion: "develop" +} + +source_reprocess: +{ + module_type: RootInput + maxEvents: 100000 # Number of events to create +} + +physics: +{ + producers: { calmod: @local::VPlaneHandler } + analyzers: { + supera: @local::SuperaModule + #digit: @local::litemc_rawdigit + @table::dldata_analyzers + } + #reco: [calmod] + #ana: [opdigit, opreco, reco2d, wire, supera, digit] + ana: [opdigit, opreco, reco2d, wire, supera] + end_paths: [ana] + #trigger_paths: [reco] + trigger_paths: [] +} + +physics.analyzers.digit.DataLookUpMap.rawdigit: ["wcNoiseFilter"]