1 #ifndef __LARLITE_LARIMAGEHIT_CXX__
2 #define __LARLITE_LARIMAGEHIT_CXX__
5 #include "LArUtil/Geometry.h"
6 #include "DataFormat/rawdigit.h"
8 #include "DataFormat/hit.h"
9 #include "DataFormat/cluster.h"
10 #include "DataFormat/event_ass.h"
21 std::cout <<
" # of clusters per plane ......... ";
23 std::cout <<
" ... Average (per-event) ";
25 double nclusters = _num_clusters_v[plane];
26 std::cout << Form(
"%g ",nclusters / ((
double)(
_num_stored)));
28 std::cout << std::endl;
30 std::cout <<
" # of clustered hits per plane ... ";
32 std::cout <<
" ... Fractions: ";
33 for(
size_t plane=0; plane<_num_clustered_hits_v.size(); ++plane) {
34 double clustered = _num_clustered_hits_v[plane];
36 std::cout << Form(
"%g%% ",clustered/(clustered+unclustered));
38 std::cout << std::endl;
45 auto geom = ::larutil::Geometry::GetME();
52 auto ev_hit = storage->get_data<event_hit>(
producer());
54 if(!ev_hit)
throw DataFormatException(
"Could not locate hit data product!");
58 std::vector<size_t> nclusters_v(alg_mgr_v.size(),0);
59 size_t nclusters_total=0;
60 for(
size_t plane=0; plane<alg_mgr_v.size(); ++plane) {
61 nclusters_v[plane] = alg_mgr_v[plane].Clusters().size();
63 nclusters_total += nclusters_v[plane];
67 ass_set.resize(nclusters_total);
68 for(
auto& ass_unit : ass_set) ass_unit.reserve(100);
70 for(
size_t hindex=0; hindex<ev_hit->size(); ++hindex) {
72 auto const& h = (*ev_hit)[hindex];
74 auto const& wid = h.WireID();
76 auto const& alg_mgr = alg_mgr_v[wid.Plane];
78 auto const& cid = alg_mgr.ClusterID(wid.Wire,h.PeakTime());
88 for(
size_t plane=0; plane<wid.Plane; ++plane) cindex += nclusters_v[plane];
90 ass_set[cindex].push_back(hindex);
93 auto ev_cluster = storage->get_data<event_cluster>(
"ImageClusterHit");
94 auto ev_ass = storage->get_data<event_ass>(
"ImageClusterHit");
96 ev_cluster->reserve(nclusters_total);
97 for(
size_t plane=0; plane<nclusters_v.size(); ++plane) {
99 for(
size_t cid=0; cid<nclusters_v[plane]; ++cid) {
101 ::larlite::cluster c;
102 c.set_view(geom->PlaneToView(plane));
103 c.set_planeID(geo::PlaneID(0,0,plane));
104 c.set_id(ev_cluster->size());
106 ev_cluster->push_back(c);
111 ev_ass->set_association(ev_cluster->id(),ev_ass->id(),ass_set);
117 auto const& geom = ::larutil::Geometry::GetME();
118 const size_t nplanes = geom->Nplanes();
120 auto ev_hit = storage->get_data<event_hit>(
producer());
122 if(ev_hit==
nullptr)
throw DataFormatException(
"Could not locate hit data product!");
124 std::vector< std::pair<size_t,size_t> > wire_range_v(nplanes,std::pair<size_t,size_t>(1e12,0));
125 std::vector< std::pair<size_t,size_t> > tick_range_v(nplanes,std::pair<size_t,size_t>(1e12,0));
127 for(
auto const& h : *ev_hit) {
129 auto const& wid = h.WireID();
131 auto& wire_range = wire_range_v[wid.Plane];
132 if(wire_range.first > wid.Wire) wire_range.first = wid.Wire;
133 if(wire_range.second < wid.Wire) wire_range.second = wid.Wire;
135 auto& tick_range = tick_range_v[wid.Plane];
136 size_t peak_time = (size_t)(h.PeakTime());
137 if(tick_range.first > peak_time ) tick_range.first = ( bool(peak_time) ? peak_time - 1 : 0 );
138 if(tick_range.second < (peak_time+1)) tick_range.second = peak_time+1;
141 for(
size_t plane=0; plane<nplanes; ++plane) {
142 auto const& wire_range = wire_range_v[plane];
143 auto const& tick_range = tick_range_v[plane];
144 size_t nticks = tick_range.second - tick_range.first + 2;
145 size_t nwires = wire_range.second - wire_range.first + 2;
146 ::larcv::ImageMeta meta((
double)nwires,(
double)nticks,nwires,nticks,wire_range.first,tick_range.first);
164 for(
auto const& h : *ev_hit) {
166 auto const& wid = h.WireID();
168 if(wid.Plane >= wire_range_v.size())
continue;
173 auto const& wire_range = wire_range_v[wid.Plane];
174 auto const& tick_range = tick_range_v[wid.Plane];
176 size_t nticks = tick_range.second - tick_range.first + 2;
177 size_t nwires = wire_range.second - wire_range.first + 2;
179 size_t y = (size_t)(h.PeakTime()+0.5) - tick_range.first;
180 size_t x = wid.Wire - wire_range.first;
182 if(y>=nticks || x>=nwires)
throw std::exception();
186 charge += (double)(mat.at<
unsigned char>(x,y));
188 if(charge>=255.) charge=255.;
189 if(charge<0.) charge=0.;
191 mat.at<
unsigned char>(x,y) = (
unsigned char)((int)charge);