35 #include <Eigen/Dense>
52 inline constexpr
T square(
const T&
x ) {
return x*
x; }
57 out <<
"( " << vector[0] <<
"," << vector[1] <<
"," << vector[2] <<
")";
64 out <<
"( " << vector[0] <<
"," << vector[1] <<
")";
69 [[maybe_unused]]
inline std::ostream&
operator << (std::ostream&
out,
const TVector3& vector )
71 out <<
"( " << vector.x() <<
"," << vector.y() <<
"," << vector.z() <<
")";
76 [[maybe_unused]]
inline std::ostream&
operator << (std::ostream& out,
const TVector2& vector )
78 out <<
"( " << vector.X() <<
"," << vector.Y() <<
")";
93 std::cout <<
"MicromegasClusterizer::Init - m_use_default_pedestal: " <<
m_use_default_pedestal << std::endl;
94 std::cout <<
"MicromegasClusterizer::Init - m_default_pedestal: " <<
m_default_pedestal << std::endl;
96 <<
"MicromegasClusterizer::Init -"
97 <<
" m_calibration_filename: "
118 auto trkrClusterContainer = findNode::getClass<TrkrClusterContainer>(dstNode,
"TRKR_CLUSTER");
119 if (!trkrClusterContainer)
126 dstNode->addNode(trkrNode);
130 auto TrkrClusterContainerNode =
new PHIODataNode<PHObject>(trkrClusterContainer,
"TRKR_CLUSTER",
"PHObject");
131 trkrNode->addNode(TrkrClusterContainerNode);
135 auto trkrClusterHitAssoc = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
136 if(!trkrClusterHitAssoc)
143 dstNode->addNode(trkrNode);
148 trkrNode->addNode(newNode);
159 for(
std::string geonodename: {
"CYLINDERGEOM_MICROMEGAS_FULL",
"CYLINDERGEOM_MICROMEGAS" } )
160 {
if(( geonode = findNode::getClass<PHG4CylinderGeomContainer>(topNode, geonodename.c_str()) ))
break; }
164 auto trkrhitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
165 assert( trkrhitsetcontainer );
168 auto trkrClusterContainer = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
169 assert( trkrClusterContainer );
172 auto trkrClusterHitAssoc = findNode::getClass<TrkrClusterHitAssoc>(topNode,
"TRKR_CLUSTERHITASSOC");
173 assert( trkrClusterHitAssoc );
176 auto acts_geometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
181 for(
auto hitset_it = hitset_range.first; hitset_it != hitset_range.second; ++hitset_it )
194 const auto acts_surface = acts_geometry->maps().getMMSurface( hitsetkey);
198 <<
"MicromegasClusterizer::process_event -"
199 <<
" could not find surface for layer " << (int)
layer <<
" tile: " << (
int) tileid
200 <<
" skipping hitset"
209 const auto segmentation_type = layergeom->get_segmentation_type();
210 const double pitch = layergeom->get_pitch();
211 const double strip_length = layergeom->get_strip_length( tileid, acts_geometry );
214 using range_list_t = std::vector<TrkrHitSet::ConstRange>;
218 const auto hit_range = hitset->
getHits();
221 auto begin = hit_range.first;
224 uint16_t previous_strip = 0;
227 for(
auto hit_it = hit_range.first; hit_it != hit_range.second; ++hit_it )
231 const auto hitkey = hit_it->first;
239 previous_strip = strip;
243 }
else if( strip - previous_strip > 1 ) {
246 ranges.push_back( std::make_pair(
begin, hit_it ) );
254 previous_strip = strip;
259 if(
begin != hit_range.second ) ranges.push_back( std::make_pair(
begin, hit_range.second ) );
262 int cluster_count = 0;
265 for(
const auto& range : ranges )
270 TVector2 local_coordinates;
271 double weight_sum = 0;
275 double coord_sum = 0;
276 double coordsquare_sum = 0;
279 unsigned int adc_sum = 0;
280 unsigned int max_adc = 0;
281 unsigned int strip_count = 0;
283 for(
auto hit_it = range.first; hit_it != range.second; ++hit_it )
287 const auto hitkey = hit_it->first;
288 const auto hit = hit_it->second;
291 trkrClusterHitAssoc->addAssoc(ckey,
hitkey );
300 const double weight =
double(hit->getAdc()) - pedestal;
303 const auto hit_adc = hit->getAdc();
304 if( hit_adc > max_adc) { max_adc = hit_adc; }
308 const auto strip_local_coordinate = layergeom->get_local_coordinates( tileid, acts_geometry, strip );
309 local_coordinates += strip_local_coordinate*weight;
310 switch( segmentation_type )
315 coord_sum += strip_local_coordinate.X()*weight;
316 coordsquare_sum +=
square(strip_local_coordinate.X())*weight;
322 coord_sum += strip_local_coordinate.Y()*weight;
323 coordsquare_sum +=
square(strip_local_coordinate.Y())*weight;
328 weight_sum += weight;
332 local_coordinates *= (1./weight_sum);
335 static const float invsqrt12 = 1./std::sqrt(12);
336 static constexpr
float error_scale_phi = 1.6;
337 static constexpr
float error_scale_z = 0.8;
339 auto coord_cov = coordsquare_sum/weight_sum -
square( coord_sum/weight_sum );
340 auto coord_error_sq = coord_cov/weight_sum;
343 double error_sq_x = 0;
344 double error_sq_y = 0;
345 switch( segmentation_type )
349 if( coord_error_sq == 0 ) coord_error_sq =
square(pitch)/12;
350 else coord_error_sq *=
square(error_scale_phi);
351 error_sq_x = coord_error_sq;
352 error_sq_y =
square(strip_length*invsqrt12);
358 if( coord_error_sq == 0 ) coord_error_sq =
square(pitch)/12;
359 else coord_error_sq *=
square(error_scale_z);
360 error_sq_x =
square(strip_length*invsqrt12);
361 error_sq_y = coord_error_sq;
367 auto cluster = std::make_unique<TrkrClusterv5>();
368 cluster->setAdc( adc_sum );
369 cluster->setMaxAdc( max_adc );
370 cluster->setLocalX(local_coordinates.X());
371 cluster->setLocalY(local_coordinates.Y());
372 cluster->setPhiError(sqrt(error_sq_x));
373 cluster->setZError(sqrt(error_sq_y));
375 switch( segmentation_type )
379 cluster->setPhiSize(strip_count);
380 cluster->setZSize(1);
386 cluster->setPhiSize(1);
387 cluster->setZSize(strip_count);
392 trkrClusterContainer->addClusterSpecifyKey( ckey, cluster.release() );