56 {
57 if (collection->size()<2) return;
58
60 ATH_MSG_DEBUG(
"The map has " << theMap.size() <<
" entries already");
61
62 IdentifierHash elementHash = collection->identifyHash();
63
64
65
66
67 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> pixelDetEleHandle(
m_pixelDetEleCollKey);
68 const InDetDD::SiDetectorElementCollection* pixelDetEle(*pixelDetEleHandle);
69 if (not pixelDetEleHandle.isValid() or pixelDetEle==nullptr) {
71 return;
72 }
73 const InDetDD::SiDetectorElement* element = pixelDetEle->getDetectorElement(elementHash);
74 const InDetDD::PixelModuleDesign* design =(
dynamic_cast<const InDetDD::PixelModuleDesign*
>(&element->
design()));
75 if (not design){
76 ATH_MSG_ERROR(
"Dynamic cast failed at line "<<__LINE__<<
" of PixelGangedAmbiguitiesFinder.cxx.");
77 return;
78 }
79 int rowsPerFE = design->rows()/2;
82 ATH_MSG_ERROR(
"The helper type is not Pixel at line "<<__LINE__<<
" of PixelGangedAmbiguitiesFinder.cxx.");
83 return;
84 }
85 const PixelID* pixelID =static_cast<const PixelID*>(pHelper);
86
87 std::vector<PixelClusterCollection::iterator> rmList;
88
89 PixelClusterCollection::iterator cluster=collection->begin();
90 PixelClusterCollection::iterator clend=collection->end();
91
92 for( ; cluster!=clend ; ++cluster){
93
94 if (
find(rmList.begin(),rmList.end(),cluster)!=rmList.end() )
continue;
95
96
97 bool hasGanged = false;
98 int rmin1=999, cmin1=999;
99 std::vector<Identifier> gangedPixels;
100 const std::vector<Identifier>& RDOs = (*cluster)->rdoList();
101
102 std::vector<Identifier>::const_iterator rdo=RDOs.begin();
103 std::vector<Identifier>::const_iterator rdoend=RDOs.end();
104 for( ; rdo != rdoend; ++rdo){
105 Identifier gangedID;
106 bool ganged =
isGanged(*rdo,element,gangedID);
107 if(ganged){
108 hasGanged = true;
109 gangedPixels.push_back(gangedID);
110 }
112 if (thiscol<cmin1) cmin1=thiscol;
114 if (thisrow<rmin1) rmin1=thisrow;
115
116 }
117
118
119 (*cluster)->setGangedPixel(hasGanged);
120
121
122 if(hasGanged){
123
125 std::vector<Identifier>::const_iterator gangedPixelsBegin = gangedPixels.begin();
126 std::vector<Identifier>::const_iterator gangedPixelsEnd = gangedPixels.end();
127 PixelClusterCollection::iterator cluster2=cluster+1;
128 for( ; cluster2!=clend; ++cluster2){
130 << std::hex << (*cluster)->identify()
131 << " and " << (*cluster2)->identify()
132 << std::dec);
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) {
139 if (!sharedGanged) {
140 for( std::vector<Identifier>::const_iterator gangedRDOs=gangedPixelsBegin;
141 gangedRDOs < gangedPixelsEnd; ++gangedRDOs ){
142 if(*rdo2 == *gangedRDOs){
143 sharedGanged = true;
144 break;
145 }
146 }
147 }
149 if (thiscol<cmin2) cmin2=thiscol;
151 if (thisrow<rmin2) rmin2=thisrow;
152
153 }
154
155 if(sharedGanged){
156
157
158
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() );
163
164
165 if ( (drow1==1 && drow2>1 && drow2<4) || (dcol2>dcol1 && cmin2<=cmin1 && cmin2+dcol2>=cmin1+dcol1)){
166
168 rmList.push_back(cluster);
170 << ": deleted " << (*cluster)->identify()
171 << std::dec);
172 break;
173 }
174 else (*cluster)->setFake(true);
175 }
176 else if ( (drow1>1 && drow1<4 && drow2==1) || (dcol1>dcol2 && cmin1<=cmin2 && cmin1+dcol1>=cmin2+dcol2)){
177
179 rmList.push_back(cluster2);
181 << ": deleted " << (*cluster2)->identify()
182 << std::dec);
183 continue;
184 }
185 else (*cluster2)->setFake(true);
186 }
187 else if ( drow2>1 || drow1>1 ) {
188 if (cmin1==cmin2){
189 rdo=RDOs.begin();
190 std::vector<std::vector<int> > myvec(dcol1);
191 for( ; rdo != rdoend; ++rdo){
194 myvec[col-cmin1].push_back(row);
195 }
196 rdo=rdos2.begin();
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);
203 }
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;
212
213 thissize++;
214 if (myvec[i][j]>=rowsPerFE) thissizeright++;
215
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;
220 }
221 thissize=thissizeright=0;
222 for (
int j=0;j<(
int)myvec2[
i].size();j++){
223 if (j!=0 && thissize==0) hasgap2=true;
224 thissize++;
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;
230
231 }
232
233 if (maxsize1>maxsize2 && maxsizeleft1>=maxsizeleft2 && maxsizeright1>=maxsizeright2 && !hasgap1) nvictory1++;
234 else if (maxsize2>maxsize1 && maxsizeleft2>=maxsizeleft1 && maxsizeright2>=maxsizeright1 && !hasgap2) nvictory2++;
235 }
236
237
238
239
240
241 if (nvictory1>nvictory2){
242
244 rmList.push_back(cluster2);
246 << ": deleted " << (*cluster2)->identify()
247 << std::dec);
248 continue;
249 }
250 else {
251 (*cluster2)->setFake(true);
252
253 }
254 }
255 else if (nvictory2>nvictory1){
256
258 rmList.push_back(cluster);
260 << ": deleted " << (*cluster)->identify()
261 << std::dec);
262 continue;
263 }
264 else {
265 (*cluster)->setFake(true);
266
267 }
268 }
269 }
270 }
271
272
273
274
275
276
277
278
279
280 if (!((*cluster)->isSplit() && (*cluster2)->isSplit()))
281 {
282 (*cluster)->setAmbiguous(true);
283 (*cluster2)->setAmbiguous(true);
284
285
286
287 theMap.insert(std::make_pair(*cluster,*cluster2));
288 theMap.insert(std::make_pair(*cluster2,*cluster));
290 << ": added ambiguity entry"
291 << std::dec);
292 }
293 }
294 }
295 }
296 }
297 ATH_MSG_DEBUG(
"The map has " << theMap.size() <<
" entries ");
298
299
300
301
302 int rmNumber=0;
303 std::vector<PixelClusterCollection::iterator>::iterator rmit=rmList.begin();
304 std::vector<PixelClusterCollection::iterator>::iterator rmend=rmList.end();
306 for ( ; rmit!=rmend ; ++rmit){
308 << std::hex << (*(*rmit-rmNumber))->
identify() << std::dec);
309 collection->erase(*rmit-rmNumber);
310 rmNumber++;
311 }
312 ATH_MSG_DEBUG(rmNumber <<
" fake clusters from ganged pixel have been removed");
313
314}
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
const AtlasDetectorID * getIdHelper() const
Returns the id helper (inline)
static bool isGanged(const Identifier &rdoID, const InDetDD::SiDetectorElement *element, Identifier &gangedID)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
BooleanProperty m_internalSolving
int eta_index(const Identifier &id) const
int phi_index(const Identifier &id) const
std::string find(const std::string &s)
return a remapped string
row
Appending html table to final .html summary file.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.