5 #include "GaudiKernel/ConcurrencyFlags.h"
14 declareInterface<NSWL1::IStripClusterTool>(
this);
25 return StatusCode::SUCCESS;
29 std::vector<std::unique_ptr<StripClusterData>>&
clusters,
30 std::vector<std::shared_ptr<std::vector<std::unique_ptr<StripData> >> > &cluster_cache)
const {
32 ATH_MSG_DEBUG(
"Cluster cache received " << cluster_cache.size());
34 bool first_strip=
true;
35 for(
const auto &this_cl : cluster_cache){
50 if (this_cl->empty()){
58 if( !readMuonSimDataCollection.
isValid() ){
59 ATH_MSG_WARNING(
"could not retrieve the sTGC SDO container: it will not be possible to associate the MC truth");
60 return StatusCode::FAILURE;
62 sdo_container = readMuonSimDataCollection.
cptr();
65 for(
const auto &strip_cl : *this_cl){
69 if(
m_isMC && first_strip) {
73 auto it = sdo_container->find(Id);
74 if(
it == sdo_container->end())
continue;
76 std::vector<MuonSimData::Deposit> deposits;
79 if (deposits.size()!=1)
ATH_MSG_WARNING(
"Multiple cluster hits for strip!");
80 if (deposits.empty()){
85 int truth_barcode = deposits[0].first.barcode();
86 double truth_localPosX = deposits[0].second.firstEntry();
87 double truth_localPosY = deposits[0].second.secondEntry();
91 double truth_globalPosX = hit_gpos.x();
92 double truth_globalPosY = hit_gpos.y();
93 double truth_globalPosZ = hit_gpos.z();
94 float truth_energy = strip_sdo.
word();
96 if(std::abs(locx-lpos.x())>.001 || std::abs(locy - lpos.y())>.001){
97 ATH_MSG_DEBUG(
"OLD locx " << locx <<
" new locx " << lpos.x() <<
" b " <<
int(locx!=lpos.x()));
98 ATH_MSG_DEBUG(
"OLD locy " << locy <<
" new locy " << lpos.y() <<
" b " <<
int(locy!=lpos.y()));
99 ATH_MSG_DEBUG(
"Cluster hit, truth barcode = " << truth_barcode);
100 ATH_MSG_DEBUG(
"Cluster hit, truth globalPosX = " << truth_globalPosX
101 <<
", truth globalPosY = " << truth_globalPosY
102 <<
", truth globalPosZ = " << truth_globalPosZ
103 <<
", truth enegy deposit = " << truth_energy);
105 <<
", truth localPosY = " << lpos.y()
106 <<
", truth enegy deposit = " << truth_energy);
110 float s_charge=strip_cl->strip_charge_6bit();
112 x_pos+=strip_cl->globX()*s_charge;
113 y_pos+=strip_cl->globY()*s_charge;
114 z_pos+=strip_cl->globZ()*s_charge;
116 x_lpos+=(strip_cl->locX())*s_charge;
117 y_lpos+=(strip_cl->locY())*s_charge;
118 z_lpos+=(strip_cl->locZ())*s_charge;
121 ATH_MSG_DEBUG(
"Cluster ------------------------------------------" );
125 ATH_MSG_DEBUG(
"Cluster strip glob X: " << strip_cl->globX());
126 ATH_MSG_DEBUG(
"Cluster strip glob Y: " << strip_cl->globY());
127 ATH_MSG_DEBUG(
"Cluster strip glob Z: " << strip_cl->globZ());
128 ATH_MSG_DEBUG(
"Cluster strip locx dist: " << locx-strip_cl->locX());
129 ATH_MSG_DEBUG(
"Cluster strip charge o dist: " << s_charge/(locx-strip_cl->locX()));
135 if ( std::abs(x_pos/
charge)<200. && std::abs(y_pos/
charge)<200.){
136 ATH_MSG_WARNING(
"Cluster ------------------------------------------" );
149 ATH_MSG_DEBUG(
"Cluster dump with X:" << x_pos <<
" Y: " << y_pos <<
" Z: " << z_pos <<
" cluster charge: " <<
charge);
150 ATH_MSG_DEBUG(
"Cluster dump with lX:" << x_lpos <<
" lY: " << y_lpos <<
" lZ: " << z_lpos <<
" cluster charge: " <<
charge);
152 auto stripClOfflData=std::make_unique<StripClusterOfflineData>(
153 this_cl->at(0)->bandId(),
154 this_cl->at(0)->trig_BCID(),
155 this_cl->at(0)->sideId(),
156 this_cl->at(0)->phiId(),
157 this_cl->at(0)->isSmall(),
158 this_cl->at(0)->moduleId(),
159 this_cl->at(0)->sectorId(),
160 this_cl->at(0)->wedge(),
161 this_cl->at(0)->layer(),
167 clusters.push_back(std::move(stripClOfflData));
169 return StatusCode::SUCCESS;
177 return StatusCode::SUCCESS;
180 std::map<uint32_t, std::vector<std::unique_ptr<StripData>> > stripMap;
182 for (
auto& st : strips) {
184 auto sideId = st->sideId();
186 auto sectorType = st->sectorType();
188 auto sectorId = st->sectorId();
190 auto etaId = st->moduleId();
192 auto wedgeId = st->wedge();
194 auto layerId = st->layer();
200 auto it = stripMap.find(cache_hash);
201 if (
it != stripMap.end()){
202 it->second.push_back(std::move(st));
205 stripMap[cache_hash].push_back(std::move(st));
210 std::vector< std::shared_ptr<std::vector<std::unique_ptr<StripData> >> > cluster_cache;
211 for (
auto &
item : stripMap) {
212 std::vector<std::unique_ptr<StripData>>& stripList =
item.second;
215 std::sort(stripList.begin(), stripList.end(), [](
const auto& s1,
const auto&
s2) { return s1->channelId()<s2->channelId(); });
217 auto hit=stripList.begin();
219 <<
" " << (*hit)->moduleId() <<
" " << (*hit)->sectorId() <<
" " << (*hit)->wedge() <<
" " << (*hit)->sideId() );
220 int first_ch=(*hit)->channelId();
223 auto cr_cluster=std::make_shared< std::vector<std::unique_ptr<StripData>> >();
225 for(
auto& this_hit : stripList){
226 if(!(this_hit)->readStrip() )
continue;
227 if( ((this_hit)->bandId()==-1 || this_hit->phiId()==-1) ){
229 <<
" " << (this_hit)->moduleId() <<
" " << (this_hit)->sectorId() <<
" " << (this_hit)->wedge() <<
" " << (this_hit)->sideId() );
235 cr_cluster->push_back(std::move(this_hit));
240 if ( (this_ch < prev_ch)) {
242 return StatusCode::FAILURE;
245 if (this_ch == prev_ch || this_ch == prev_ch+1) cr_cluster->push_back(std::move(this_hit));
247 cluster_cache.push_back(std::move(cr_cluster));
248 cr_cluster=std::make_shared<std::vector<std::unique_ptr<StripData>>>();
249 cr_cluster->push_back(std::move(this_hit));
255 if(!cr_cluster->empty()) cluster_cache.push_back(std::move(cr_cluster));
258 ATH_MSG_DEBUG(
"Found :" << cluster_cache.size() <<
" clusters");
260 cluster_cache.clear();
262 return StatusCode::SUCCESS;