56 const int nlayers = raypairs.size();
62 const auto& pitches = coords.pitch_dirs();
63 const auto& centers = coords.centers();
64 const auto& pitch_mags = coords.pitch_mags();
68 std::vector< std::vector<Activity::value_t> > measures(nlayers);
72 std::normal_distribution<double> spread(0.0,
gaussian);
74 for (
int idepo=0;idepo<
ndepos;++idepo) {
76 for (
int iele=0; iele<
neles; ++iele) {
77 Point delta(0, spread(generator), spread(generator));
78 points.push_back(cp+delta);
83 for (
size_t ipt=0; ipt<points.size(); ++ipt ) {
84 const auto&
p = points[ipt];
86 for (
int ilayer = 0; ilayer<nlayers; ++ilayer) {
88 const auto& pit = pitches[ilayer];
89 const auto& cen = centers[ilayer];
90 const auto rel =
p-cen;
91 const int pit_ind = pit.dot(rel)/pitch_mags[ilayer];
92 auto&
m = measures[ilayer];
93 if ((
int)
m.size() <= pit_ind) {
94 m.resize(pit_ind+1, 0.0);
101 for (
int ilayer=0; ilayer<nlayers; ++ilayer) {
102 draw_layer(coords, ilayer, pitch_mags[ilayer],
103 pitches[ilayer], centers[ilayer], measures[ilayer]);
110 for (
size_t ipt=0; ipt<points.size(); ++ipt ) {
111 const auto&
p = points[ipt];
115 for (
int ilayer = 0; ilayer<nlayers; ++ilayer) {
116 auto&
m = measures[ilayer];
118 for (
size_t ind=0; ind<
m.size(); ++ind) {
119 if (
m[ind] <= 0.0) {
continue; }
120 info(
"L{} [{}] {}", ilayer, ind,
m[ind]);
125 auto strips =
activity.make_strips();
129 auto tot = std::accumulate(
m.begin(),
m.end(), 0.0);
130 info(
"L{} activity={} in: {} strips",
activity.layer(), tot, strips.size());
134 for (
int ilayer = 0; ilayer<nlayers; ++ilayer) {
135 const auto&
activity = activities[ilayer];
136 info(
"Tiling layer {} with {} blobs: {}",
137 ilayer, blobs.size(),
activity.as_string());
144 warn(
"lost m'blobs!");
155 for (
const auto&
activity: activities) {
156 auto strips =
activity.make_strips();
171 for (
int ilayer = 2; ilayer<nlayers; ++ilayer) {
173 auto&
m = measures[ilayer];
178 for (
size_t mind=0; mind <
m.size(); ++mind) {
179 const float meas =
m[mind];
180 if (meas <= 0) {
continue; }
181 Grouping::ident_t ident =
make_ident(mind, ilayer);
182 info(
"ilayer:{} mind:{} indent:{} meas:{}", ilayer, mind, ident, meas);
183 grouping.
add(
'm', ident, { ident }, meas);
187 for (
size_t bind = 0; bind < blobs.size(); ++bind) {
188 const auto& blob = blobs[bind];
189 std::vector<Grouping::ident_t> wids;
190 for (
const auto& strip : blob.strips()) {
191 if (strip.layer != ilayer) {
194 for (
auto wind = strip.bounds.first; wind < strip.bounds.second; ++wind) {
199 const float blob_value = 0.0;
201 grouping.
add(
's', bind, wids, blob_value, blob_weight);
204 const auto&
g = grouping.
graph();
205 auto labels = [&](std::ostream& out,
const auto& vtx) {
206 char typ =
g[vtx].ntype;
207 int lid =
g[vtx].ident % 1000;
209 out <<
"[label=\"s" << lid <<
"\"]";
212 out <<
"[label=\"m" << lid <<
"=" <<
g[vtx].value <<
"\"]";
215 out <<
"[label=\"w" << lid <<
"\"]";
220 std::ofstream dotfile (dotfilename.c_str());
221 boost::write_graphviz(dotfile,
g,
labels);
222 cerr << dotfilename <<
"\n";
224 auto clusters = grouping.
clusters();
225 solving.
add(clusters);
228 auto solution = solving.
solve();
230 for (
const auto& it : solution) {
231 std::cerr << it.first <<
": " << it.second <<
std::endl;
234 const auto&
g = solving.
graph();
235 auto labels = [&](std::ostream& out,
const auto& vtx) {
236 char typ =
g[vtx].ntype;
238 out <<
"[label=\"s" <<
g[vtx].ident <<
"=" << Form(
"%.1f",
g[vtx].
value) <<
"\"]";
241 out <<
"[label=\"m" <<
"=" <<
g[vtx].value <<
"\"]";
246 std::ofstream dotfile (dotfilename.c_str());
247 boost::write_graphviz(dotfile,
g,
labels);
248 cerr << dotfilename <<
"\n";
void draw_points_blobs_solved(Coordinates &coords, Printer &print, const std::vector< Point > &points, const blobs_t &blobs, const std::unordered_map< size_t, float > &blob_charge)
const double pitch_magnitude
void draw_raygrid(Printer &print, const Coordinates &coords, const ray_pair_vector_t &raypairs)
size_t drop_invalid(blobs_t &blobs)
free functions
def activity(output, slices, slice_line, cluster_tap_file)
void draw_strips(Coordinates &coords, const strips_t &strips, bool outline=true)
std::enable_if< internal::is_string< String >::value >::type print(std::FILE *f, const text_style &ts, const String &format_str, const Args &...args)
virtual void add(char ntype, ident_t chid, std::vector< ident_t > wids, float value, float weight=1.0)
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
static int max(int a, int b)
void draw_points_blobs(Coordinates &coords, Printer &print, const std::vector< Point > &points, const blobs_t &blobs)
TH1F * draw_frame(TCanvas &canvas, std::string title)
std::vector< Blob > blobs_t
void draw_layer(Coordinates &coords, int ilayer, double pitch_mag, const Point &pitch, const Point ¢er, const std::vector< double > &measure)
const GenericPointer< typename T::ValueType > T2 value
Grouping::ident_t make_ident(int index, int layer, int face=0)
static double blob_weight(IBlob::pointer iblob, ISlice::pointer islice, const cluster_indexed_graph_t &grind)
std::vector< Activity > activities_t
void draw_point(const Point &p, float size=1, int style=20, int color=1)
ray_pair_vector_t make_raypairs(double width=100, double height=100, double pitch_mag=3, double angle=60.0 *M_PI/180.0)
void dump(const IFrame::pointer frame)
void add(const Grouping::clusterset_t &cset)
QTextStream & endl(QTextStream &s)