27 #include <unordered_set>
36 const std::string &
name,
37 const IInterface *
parent) :
48 return StatusCode::SUCCESS;
55 ATH_MSG_DEBUG(
"------------------- Clusterization Statistics ------------------------");
57 ATH_MSG_DEBUG(
"----------------------------------------------------------------------");
58 return StatusCode::SUCCESS;
75 const std::vector<int>& totgroup,
76 const std::vector<int>& lvl1group,
92 throw std::runtime_error(
"Wrong design at MergedPixelsTool");
94 int rowMin =
int(2*(design->width()/design->phiPitch()))+1;
96 int colMin =
int(2*(design->length()/design->etaPitch()))+1;
98 int qRowMin = 0;
int qRowMax = 0;
99 int qColMin = 0;
int qColMax = 0;
103 std::vector<Identifier> DVid;
104 DVid.reserve(
group.size() );
105 std::vector<Identifier>::const_iterator rdosBegin =
group.begin();
106 std::vector<Identifier>::const_iterator rdosEnd =
group.end();
107 std::vector<int>::const_iterator
tot = totgroup.begin();
108 std::vector<int>::const_iterator lvl1= lvl1group.begin();
111 bool hasGanged =
false;
112 for (; rdosBegin!= rdosEnd; ++rdosBegin) {
115 if ( (*lvl1) < lvl1min ) lvl1min=(*lvl1);
123 hasGanged = hasGanged ||
127 (design->positionFromColumnRow(
col,
row));
128 sumOfPositions += siLocalPosition;
133 if (
row == rowMin) qRowMin += realtot;
139 if (
row == rowMax) qRowMax += realtot;
145 if (
col == colMin) qColMin += realtot;
151 if (
col == colMax) qColMax += realtot;
159 const int numberOfPixels =
group.size();
163 const int colWidth = colMax-colMin+1;
164 const int rowWidth = rowMax-rowMin+1;
170 if(qRowMin+qRowMax > 0) etaRow = qRowMax/
float(qRowMin+qRowMax);
171 if(qColMin+qColMax > 0) etaCol = qColMax/
float(qColMin+qColMax);
173 double etaWidth = design->widthFromColumnRange(colMin, colMax);
174 double phiWidth = design->widthFromRowRange(rowMin, rowMax);
179 if(
m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){
192 const float sensorThickness = element->
thickness();
197 deltay = sensorThickness*std::abs(globalPos.z())/globalPos.perp();
198 if(deltay > (design->etaPitch()) ) deltay = design->etaPitch();
207 centroid = 0.25*(pos1+pos2+pos3+pos4)+
209 ATH_MSG_VERBOSE(
"Barrel cluster with global position r= " << globalPos.perp() <<
" and z = " << globalPos.z());
213 if(
m_posStrategy == 10 && !hasGanged && etaRow>0 && etaCol > 0){
217 ATH_MSG_ERROR(
"Detected position strategy = 10, this is an obsolete setting for CTB analysis and is not supported anymore since Athena 15.4.0");
218 ATH_MSG_ERROR(
"...reverting to default setting: position strategy = 0");
223 if(
m_posStrategy == 20 && !hasGanged && etaRow>0 && etaCol > 0){
228 design->positionFromColumnRow(colMin,rowMin);
230 design->positionFromColumnRow(colMax,rowMin);
232 design->positionFromColumnRow(colMin,rowMax);
234 design->positionFromColumnRow(colMax,rowMax);
235 centroid = 0.25*(pos1+pos2+pos3+pos4)+
237 deltax*(etaRow-0.5),0.);
245 <<
" x " << rowWidth);
249 << (position)[0] <<
" "
253 return PixelCluster(
id, position, std::move(DVid), lvl1min,
254 std::vector<int>(totgroup), siWidth, element,
258 id, position, std::move(DVid), lvl1min, std::vector<int>(totgroup),
260 splitProb1, splitProb2, calibData, offlineCalibData);
273 const EventContext& ctx)
const {
276 if (element ==
nullptr){
280 std::vector<UnpackedPixelRDO> collectionID =
281 m_pixelRDOTool->getUnpackedPixelRDOs(collection, pixelID, element, ctx);
285 if(collectionID.empty())
return nullptr;
286 if(collectionID.size() > 1) std::sort(collectionID.begin(),collectionID.end(),
pixel_less);
290 std::vector<network> connections(collectionID.size());
294 int collectionSize = collectionID.size();
302 for(
int currentPixel = 0; currentPixel!=collectionSize-1; ++currentPixel) {
304 int row = collectionID.at(currentPixel).ROW;
305 int col = collectionID.at(currentPixel).COL;
307 auto & currentConnection = connections.at(currentPixel);
308 for(
int otherPixel = currentPixel+1; otherPixel!=collectionSize; ++otherPixel) {
309 auto & otherConnection = connections.at(otherPixel);
310 int deltaCol = std::abs(collectionID.at(otherPixel).COL -
col);
311 int deltaRow = std::abs(collectionID.at(otherPixel).ROW -
row);
331 if( (deltaCol+deltaRow) == 1 or (
m_addCorners and deltaCol == 1 and deltaRow == 1) ) {
332 int NC1 = currentConnection.NC;
333 int NC2 = otherConnection.NC;
334 int maxPossible = currentConnection.CON.size() - 1;
335 if ((NC1>maxPossible) or (NC2>maxPossible)){
336 std::string
m=
"attempt to access connection array of dimension 8 at idx "+
std::to_string(currentConnection.NC);
340 currentConnection.CON.at(currentConnection.NC++) = otherPixel;
341 otherConnection.CON.at(otherConnection.NC++) = currentPixel ;
343 if(++NB==maxElements) {
354 for(
int currentPixel=0; currentPixel!=collectionSize; ++currentPixel) {
355 if(collectionID.at(currentPixel).NCL < 0) {
356 collectionID.at(currentPixel).NCL = Ncluster;
364 if(--collectionSize > 1) {
365 for(
int i(1);
i<collectionSize; ++
i ) {
369 while(collectionID.at(j).NCL > U.
NCL) {
370 collectionID.at(j+1)=collectionID.at(j);
373 collectionID.at(j+1)=U;
385 clusterCollection->setIdentifier(elementID);
386 clusterCollection->reserve(Ncluster);
388 std::vector<Identifier> DVid = {collectionID.at(0).ID };
389 std::vector<int> Totg = {collectionID.at(0).TOT};
390 std::vector<int> Lvl1 = {collectionID.at(0).LVL1};
392 int clusterNumber = 0;
395 DVid.reserve(collectionID.back().NCL);
396 Totg.reserve(collectionID.back().NCL);
397 Lvl1.reserve(collectionID.back().NCL);
405 calibData = *calibDataHandle;
411 offlineCalibData = *offlineCalibDataHandle;
414 for(
int i=1;
i<=collectionSize; ++
i) {
415 if(
i!=collectionSize and collectionID.at(
i).NCL==NCL0) {
416 DVid.push_back(collectionID.at(
i).ID );
417 Totg.push_back(collectionID.at(
i).TOT);
418 Lvl1.push_back(collectionID.at(
i).LVL1);
430 makeCluster(DVid, Totg, Lvl1, element, pixelID, ++clusterNumber,
431 false, 0.0, 0.0, calibData, offlineCalibData);
436 makeCluster(DVid, Totg, Lvl1, element, pixelID, ++clusterNumber,
437 false, 0.0, 0.0, calibData, offlineCalibData);
441 clusterCollection->size());
442 clusterCollection->push_back(cluster);
445 if (
i!=collectionSize) {
446 NCL0 = collectionID.at(
i).NCL ;
447 DVid.clear(); DVid = {collectionID.at(
i).ID };
448 Totg.clear(); Totg = {collectionID.at(
i).TOT};
449 Lvl1.clear(); Lvl1 = {collectionID.at(
i).LVL1};
454 return clusterCollection;
459 const std::vector<network>& connections,
460 std::vector<UnpackedPixelRDO>& collectionID)
const {
461 for(
int i=0;
i!=connections.at(
r).
NC; ++
i) {
462 const int k = connections.at(
r).CON.at(
i);
463 if(collectionID.at(
k).NCL < 0) {
464 collectionID.at(
k).NCL = Ncluster;