20 #include "GaudiKernel/SmartDataPtr.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/IToolSvc.h"
29 using namespace InDet;
33 const std::string &
type,
34 const std::string &
name,
35 const IInterface *
parent) :
38 declareInterface<PixelGangedAmbiguitiesFinder>(
this);
44 return StatusCode::SUCCESS;
57 if (collection->size()<2)
return;
60 ATH_MSG_DEBUG(
"The map has " << theMap.size() <<
" entries already");
62 IdentifierHash elementHash = collection->identifyHash();
69 if (not pixelDetEleHandle.
isValid() or pixelDetEle==
nullptr) {
76 ATH_MSG_ERROR(
"Dynamic cast failed at line "<<__LINE__<<
" of PixelGangedAmbiguitiesFinder.cxx.");
79 int rowsPerFE = design->rows()/2;
82 ATH_MSG_ERROR(
"The helper type is not Pixel at line "<<__LINE__<<
" of PixelGangedAmbiguitiesFinder.cxx.");
87 std::vector<PixelClusterCollection::iterator> rmList;
92 for( ; cluster!=clend ; ++cluster){
94 if (
find(rmList.begin(),rmList.end(),cluster)!=rmList.end() )
continue;
97 bool hasGanged =
false;
98 int rmin1=999, cmin1=999;
99 std::vector<Identifier> gangedPixels;
100 const std::vector<Identifier>& RDOs = (*cluster)->rdoList();
102 std::vector<Identifier>::const_iterator rdo=RDOs.begin();
103 std::vector<Identifier>::const_iterator rdoend=RDOs.end();
104 for( ; rdo != rdoend; ++rdo){
106 bool ganged =
isGanged(*rdo,element,gangedID);
109 gangedPixels.push_back(gangedID);
112 if (thiscol<cmin1) cmin1=thiscol;
114 if (thisrow<rmin1) rmin1=thisrow;
119 (*cluster)->setGangedPixel(hasGanged);
125 std::vector<Identifier>::const_iterator gangedPixelsBegin = gangedPixels.begin();
126 std::vector<Identifier>::const_iterator gangedPixelsEnd = gangedPixels.end();
128 for( ; cluster2!=clend; ++cluster2){
130 << std::hex << (*cluster)->identify()
131 <<
" and " << (*cluster2)->identify()
133 bool sharedGanged =
false;
134 int rmin2=999, cmin2=999;
135 const std::vector<Identifier>& rdos2 = (*cluster2)->rdoList();
136 std::vector<Identifier>::const_iterator rdo2=rdos2.begin();
137 std::vector<Identifier>::const_iterator rdo2end=rdos2.end();
138 for( ; rdo2!=rdo2end; ++rdo2) {
140 for( std::vector<Identifier>::const_iterator gangedRDOs=gangedPixelsBegin;
141 gangedRDOs < gangedPixelsEnd; ++gangedRDOs ){
142 if(*rdo2 == *gangedRDOs){
149 if (thiscol<cmin2) cmin2=thiscol;
151 if (thisrow<rmin2) rmin2=thisrow;
159 int drow1=lrint((**cluster).width().colRow().x() );
160 int drow2=lrint((**cluster2).width().colRow().x() );
161 int dcol1=lrint((**cluster).width().colRow().y() );
162 int dcol2=lrint((**cluster2).width().colRow().y() );
165 if ( (drow1==1 && drow2>1 && drow2<4) || (dcol2>dcol1 && cmin2<=cmin1 && cmin2+dcol2>=cmin1+dcol1)){
168 rmList.push_back(cluster);
170 <<
": deleted " << (*cluster)->identify()
174 else (*cluster)->setFake(
true);
176 else if ( (drow1>1 && drow1<4 && drow2==1) || (dcol1>dcol2 && cmin1<=cmin2 && cmin1+dcol1>=cmin2+dcol2)){
179 rmList.push_back(cluster2);
181 <<
": deleted " << (*cluster2)->identify()
185 else (*cluster2)->setFake(
true);
187 else if ( drow2>1 || drow1>1 ) {
190 std::vector<std::vector<int> > myvec(dcol1);
191 for( ; rdo != rdoend; ++rdo){
194 myvec[
col-cmin1].push_back(
row);
197 int dcol2=lrint((**cluster2).width().colRow().y() );
198 std::vector<std::vector<int> > myvec2(dcol2);
199 for( ; rdo != rdo2end; ++rdo){
202 myvec2[
col-cmin2].push_back(
row);
204 for (
auto &
i : myvec)
if (!
i.empty()) std::sort(
i.begin(),
i.end());
205 for (
auto &
i : myvec2)
if (!
i.empty()) std::sort(
i.begin(),
i.end());
206 int nvictory1=0,nvictory2=0;
207 for (
int i=0;
i<(
int)myvec.size();
i++){
208 int maxsize1=0,maxsize2=0,maxsizeleft1=0,maxsizeright1=0,maxsizeleft2=0,maxsizeright2=0,thissize=0,thissizeright=0;
209 bool hasgap1=
false,hasgap2=
false;
210 for (
int j=0;j<(
int)myvec[
i].
size();j++){
211 if (j!=0 && thissize==0) hasgap1=
true;
214 if (myvec[
i][j]>=rowsPerFE) thissizeright++;
216 if (thissize>maxsize1) maxsize1=thissize;
217 if (myvec[
i][j]<rowsPerFE && thissize>maxsizeleft1) maxsizeleft1=thissize;
218 if (myvec[
i][j]>=rowsPerFE && thissizeright>maxsizeright1) maxsizeright1=thissizeright;
219 if (j==(
int)myvec[
i].size()-1 || myvec[
i][j+1]!=myvec[
i][j]+1) thissize=thissizeright=0;
221 thissize=thissizeright=0;
222 for (
int j=0;j<(
int)myvec2[
i].
size();j++){
223 if (j!=0 && thissize==0) hasgap2=
true;
225 if (myvec2[
i][j]>=rowsPerFE) thissizeright++;
226 if (thissize>maxsize2) maxsize2=thissize;
227 if (myvec2[
i][j]<rowsPerFE && thissize>maxsizeleft2) maxsizeleft2=thissize;
228 if (myvec2[
i][j]>=rowsPerFE && thissizeright>maxsizeright2) maxsizeright2=thissizeright;
229 if (j==(
int)myvec2[
i].size()-1 || myvec2[
i][j+1]!=myvec2[
i][j]+1) thissize=thissizeright=0;
233 if (maxsize1>maxsize2 && maxsizeleft1>=maxsizeleft2 && maxsizeright1>=maxsizeright2 && !hasgap1) nvictory1++;
234 else if (maxsize2>maxsize1 && maxsizeleft2>=maxsizeleft1 && maxsizeright2>=maxsizeright1 && !hasgap2) nvictory2++;
241 if (nvictory1>nvictory2){
244 rmList.push_back(cluster2);
246 <<
": deleted " << (*cluster2)->identify()
251 (*cluster2)->setFake(
true);
255 else if (nvictory2>nvictory1){
258 rmList.push_back(cluster);
260 <<
": deleted " << (*cluster)->identify()
265 (*cluster)->setFake(
true);
280 if (!((*cluster)->isSplit() && (*cluster2)->isSplit()))
282 (*cluster)->setAmbiguous(
true);
283 (*cluster2)->setAmbiguous(
true);
287 theMap.insert(std::make_pair(*cluster,*cluster2));
288 theMap.insert(std::make_pair(*cluster2,*cluster));
290 <<
": added ambiguity entry"
297 ATH_MSG_DEBUG(
"The map has " << theMap.size() <<
" entries ");
305 std::sort(rmit,rmend);
306 for ( ; rmit!=rmend ; ++rmit){
308 << std::hex << (*(*rmit-rmNumber))->
identify() << std::dec);
309 collection->erase(*rmit-rmNumber);
312 ATH_MSG_DEBUG(rmNumber <<
" fake clusters from ganged pixel have been removed");
330 if ( gangedCellID==cellID ) gangedCellID = element->
connectedCell (cellID,0);