5 #include "GaudiKernel/ConcurrencyFlags.h"
13 m_detManager(nullptr),
16 declareInterface<NSWL1::IStripClusterTool>(
this);
23 << std::setfill(
' ') << std::setiosflags(std::ios::right) );
28 const INamedInterface* pnamed =
dynamic_cast<const INamedInterface*
>(
parent);
29 const std::string& algo_name = pnamed->name();
32 if (Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1) {
33 ATH_MSG_ERROR(
"DoNtuple is not possible in multi-threaded mode");
34 return StatusCode::FAILURE;
40 if ( algo_name==
"NSWL1Simulation" ){
41 SmartIF<ITHistSvc> tHistSvc{service(
"THistSvc")};
44 std::string ntuple_name = algo_name+
"Tree";
54 return StatusCode::SUCCESS;
58 if( inc.type()==IncidentType::BeginEvent ) {
65 m_cl_charge =
nullptr;
76 m_cl_truth_x =
nullptr;
77 m_cl_truth_y =
nullptr;
78 m_cl_truth_z =
nullptr;
79 m_cl_truth_lx =
nullptr;
80 m_cl_truth_ly =
nullptr;
81 m_cl_truth_lz =
nullptr;
82 m_cl_truth_E =
nullptr;
83 m_cl_truth_n =
nullptr;
85 m_cl_isSmall =
nullptr;
87 m_cl_sector =
nullptr;
88 m_cl_module =
nullptr;
90 m_cl_bandId =
nullptr;
93 return StatusCode::SUCCESS;
98 m_cl_charge =
new std::vector< int >();
99 m_cl_size =
new std::vector< int >();
100 m_cl_x=
new std::vector< float >();
101 m_cl_y=
new std::vector< float >();
102 m_cl_z=
new std::vector< float >();
103 m_cl_lx=
new std::vector< float >();
104 m_cl_ly=
new std::vector< float >();
105 m_cl_lz=
new std::vector< float >();
106 m_cl_ltgx=
new std::vector< float >();
107 m_cl_ltgy=
new std::vector< float >();
108 m_cl_ltgz=
new std::vector< float >();
109 m_cl_truth_x=
new std::vector<float >();
110 m_cl_truth_y=
new std::vector<float >();
111 m_cl_truth_z=
new std::vector<float>();
112 m_cl_truth_lx=
new std::vector<float >();
113 m_cl_truth_ly=
new std::vector<float >();
114 m_cl_truth_lz=
new std::vector<float>();
115 m_cl_truth_E=
new std::vector<float >();
116 m_cl_truth_n=
new std::vector<int >();
117 m_cl_side=
new std::vector<int>();
118 m_cl_isSmall=
new std::vector<int>();
119 m_cl_wedge=
new std::vector<int>();
120 m_cl_sector=
new std::vector<int>();
121 m_cl_module=
new std::vector<int>();
122 m_cl_layer=
new std::vector<int>();
123 m_cl_bandId=
new std::vector<int>();
124 m_cl_phiId=
new std::vector<int>();
127 std::string ToolName =
name().substr(
name().
find(
"::")+2,std::string::npos );
128 const char*
n = ToolName.c_str();
158 return StatusCode::SUCCESS;
166 m_cl_charge->clear();
177 m_cl_truth_x->clear();
178 m_cl_truth_y->clear();
179 m_cl_truth_z->clear();
180 m_cl_truth_E->clear();
181 m_cl_truth_n->clear();
182 m_cl_truth_lx->clear();
183 m_cl_truth_ly->clear();
184 m_cl_truth_lz->clear();
186 m_cl_isSmall->clear();
188 m_cl_sector->clear();
189 m_cl_module->clear();
191 m_cl_bandId->clear();
196 std::vector<std::unique_ptr<StripClusterData>>&
clusters,
197 std::vector<std::shared_ptr<std::vector<std::unique_ptr<StripData> >> > &cluster_cache)
const {
199 ATH_MSG_DEBUG(
"Cluster cache received " << cluster_cache.size());
201 bool first_strip=
true;
202 for(
const auto &this_cl : cluster_cache){
217 if (this_cl->empty()){
225 if( !readMuonSimDataCollection.
isValid() ){
226 ATH_MSG_WARNING(
"could not retrieve the sTGC SDO container: it will not be possible to associate the MC truth");
227 return StatusCode::FAILURE;
229 sdo_container = readMuonSimDataCollection.
cptr();
232 for(
const auto &strip_cl : *this_cl){
236 if(
m_isMC && first_strip) {
240 auto it = sdo_container->find(Id);
241 if(
it == sdo_container->end())
continue;
243 std::vector<MuonSimData::Deposit> deposits;
246 if (deposits.size()!=1)
ATH_MSG_WARNING(
"Multiple cluster hits for strip!");
247 if (deposits.empty()){
252 int truth_barcode = deposits[0].first.barcode();
253 double truth_localPosX = deposits[0].second.firstEntry();
254 double truth_localPosY = deposits[0].second.secondEntry();
258 double truth_globalPosX = hit_gpos.x();
259 double truth_globalPosY = hit_gpos.y();
260 double truth_globalPosZ = hit_gpos.z();
261 float truth_energy = strip_sdo.
word();
263 if(std::abs(locx-lpos.x())>.001 || std::abs(locy - lpos.y())>.001){
264 ATH_MSG_DEBUG(
"OLD locx " << locx <<
" new locx " << lpos.x() <<
" b " <<
int(locx!=lpos.x()));
265 ATH_MSG_DEBUG(
"OLD locy " << locy <<
" new locy " << lpos.y() <<
" b " <<
int(locy!=lpos.y()));
266 ATH_MSG_DEBUG(
"Cluster hit, truth barcode = " << truth_barcode);
267 ATH_MSG_DEBUG(
"Cluster hit, truth globalPosX = " << truth_globalPosX
268 <<
", truth globalPosY = " << truth_globalPosY
269 <<
", truth globalPosZ = " << truth_globalPosZ
270 <<
", truth enegy deposit = " << truth_energy);
272 <<
", truth localPosY = " << lpos.y()
273 <<
", truth enegy deposit = " << truth_energy);
276 m_cl_truth_x->push_back( hit_gpos.x() );
277 m_cl_truth_y->push_back( hit_gpos.y() );
278 m_cl_truth_z->push_back( hit_gpos.z() );
280 m_cl_truth_lx->push_back( lpos.x() );
281 m_cl_truth_ly->push_back( lpos.y() );
282 m_cl_truth_lz->push_back( 0 );
283 m_cl_truth_E->push_back( truth_energy );
288 float s_charge=strip_cl->strip_charge_6bit();
290 x_pos+=strip_cl->globX()*s_charge;
291 y_pos+=strip_cl->globY()*s_charge;
292 z_pos+=strip_cl->globZ()*s_charge;
294 x_lpos+=(strip_cl->locX())*s_charge;
295 y_lpos+=(strip_cl->locY())*s_charge;
296 z_lpos+=(strip_cl->locZ())*s_charge;
299 ATH_MSG_DEBUG(
"Cluster ------------------------------------------" );
303 ATH_MSG_DEBUG(
"Cluster strip glob X: " << strip_cl->globX());
304 ATH_MSG_DEBUG(
"Cluster strip glob Y: " << strip_cl->globY());
305 ATH_MSG_DEBUG(
"Cluster strip glob Z: " << strip_cl->globZ());
306 ATH_MSG_DEBUG(
"Cluster strip locx dist: " << locx-strip_cl->locX());
307 ATH_MSG_DEBUG(
"Cluster strip charge o dist: " << s_charge/(locx-strip_cl->locX()));
313 if ( std::abs(x_pos/
charge)<200. && std::abs(y_pos/
charge)<200.){
314 ATH_MSG_WARNING(
"Cluster ------------------------------------------" );
328 m_cl_x->push_back(x_pos);
329 m_cl_y->push_back(y_pos);
330 m_cl_z->push_back(z_pos);
332 m_cl_lx->push_back(x_lpos);
333 m_cl_ly->push_back(y_lpos);
334 m_cl_lz->push_back(z_lpos);
335 m_cl_charge->push_back(
charge);
336 m_cl_size->push_back(n_strip);
338 m_cl_side->push_back(this_cl->at(0)->sideId() );
339 m_cl_isSmall->push_back(this_cl->at(0)->isSmall() );
340 m_cl_wedge->push_back(this_cl->at(0)->wedge());
341 m_cl_sector->push_back(this_cl->at(0)->sectorId());
342 m_cl_module->push_back(this_cl->at(0)->moduleId() );
343 m_cl_layer->push_back(this_cl->at(0)->layer());
344 m_cl_bandId->push_back(this_cl->at(0)->bandId());
345 m_cl_phiId->push_back(this_cl->at(0)->phiId());
347 ATH_MSG_DEBUG(
"Cluster dump with X:" << x_pos <<
" Y: " << y_pos <<
" Z: " << z_pos <<
" cluster charge: " <<
charge);
348 ATH_MSG_DEBUG(
"Cluster dump with lX:" << x_lpos <<
" lY: " << y_lpos <<
" lZ: " << z_lpos <<
" cluster charge: " <<
charge);
350 auto stripClOfflData=std::make_unique<StripClusterOfflineData>(
351 this_cl->at(0)->bandId(),
352 this_cl->at(0)->trig_BCID(),
353 this_cl->at(0)->sideId(),
354 this_cl->at(0)->phiId(),
355 this_cl->at(0)->isSmall(),
356 this_cl->at(0)->moduleId(),
357 this_cl->at(0)->sectorId(),
358 this_cl->at(0)->wedge(),
359 this_cl->at(0)->layer(),
365 clusters.push_back(std::move(stripClOfflData));
369 return StatusCode::SUCCESS;
377 return StatusCode::SUCCESS;
380 std::map<uint32_t, std::vector<std::unique_ptr<StripData>> > stripMap;
382 for (
auto& st : strips) {
384 auto sideId = st->sideId();
386 auto sectorType = st->sectorType();
388 auto sectorId = st->sectorId();
390 auto etaId = st->moduleId();
392 auto wedgeId = st->wedge();
394 auto layerId = st->layer();
400 auto it = stripMap.find(cache_hash);
401 if (
it != stripMap.end()){
402 it->second.push_back(std::move(st));
405 stripMap[cache_hash].push_back(std::move(st));
410 std::vector< std::shared_ptr<std::vector<std::unique_ptr<StripData> >> > cluster_cache;
411 for (
auto &
item : stripMap) {
412 std::vector<std::unique_ptr<StripData>>& stripList =
item.second;
415 std::sort(stripList.begin(), stripList.end(), [](
const auto& s1,
const auto&
s2) { return s1->channelId()<s2->channelId(); });
417 auto hit=stripList.begin();
419 <<
" " << (*hit)->moduleId() <<
" " << (*hit)->sectorId() <<
" " << (*hit)->wedge() <<
" " << (*hit)->sideId() );
420 int first_ch=(*hit)->channelId();
423 auto cr_cluster=std::make_shared< std::vector<std::unique_ptr<StripData>> >();
425 for(
auto& this_hit : stripList){
426 if(!(this_hit)->readStrip() )
continue;
427 if( ((this_hit)->bandId()==-1 || this_hit->phiId()==-1) ){
429 <<
" " << (this_hit)->moduleId() <<
" " << (this_hit)->sectorId() <<
" " << (this_hit)->wedge() <<
" " << (this_hit)->sideId() );
435 cr_cluster->push_back(std::move(this_hit));
440 if ( (this_ch < prev_ch)) {
442 return StatusCode::FAILURE;
445 if (this_ch == prev_ch || this_ch == prev_ch+1) cr_cluster->push_back(std::move(this_hit));
447 cluster_cache.push_back(std::move(cr_cluster));
448 cr_cluster=std::make_shared<std::vector<std::unique_ptr<StripData>>>();
449 cr_cluster->push_back(std::move(this_hit));
455 if(!cr_cluster->empty()) cluster_cache.push_back(std::move(cr_cluster));
458 ATH_MSG_DEBUG(
"Found :" << cluster_cache.size() <<
" clusters");
460 cluster_cache.clear();
462 return StatusCode::SUCCESS;